From ddb1cbc831b6d13b985d91022f01e955e24ae871 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 8 Mar 2026 15:47:16 +0100 Subject: [CHORE] Patching TOML manifest parser to avoid null deref. Signed-off-by: Amlal El Mahrouss --- src/CommandLine/CLI.cpp | 79 +++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 39 deletions(-) (limited to 'src/CommandLine/CLI.cpp') diff --git a/src/CommandLine/CLI.cpp b/src/CommandLine/CLI.cpp index 5645728..b942178 100644 --- a/src/CommandLine/CLI.cpp +++ b/src/CommandLine/CLI.cpp @@ -9,8 +9,8 @@ #include #include #include -#include #include +#include #include constexpr auto kNeBuildFileJson = "Jbuild.json"; @@ -22,7 +22,7 @@ int main(int argc, char** argv) { NeBuild::BuildConfig config; std::vector jobs; - + for (size_t index{1}; index < argc; ++index) { std::string index_path = argv[index]; @@ -37,57 +37,58 @@ int main(int argc, char** argv) { return EXIT_SUCCESS; } - auto index_cpy = index; + auto index_cpy = index; std::mutex mutex; - jobs.push_back(std::thread{[&mutex, &index, &index_cpy, &argc, &argv, &config](std::string index_path) -> void { - std::unique_lock lk{mutex}; - std::unique_ptr builder; + jobs.push_back(std::thread{ + [&mutex, &index, &index_cpy, &argc, &argv, &config](std::string index_path) -> void { + std::unique_lock lk{mutex}; + std::unique_ptr builder; - constexpr auto kJsonExtension = ".json"; + constexpr auto kJsonExtension = ".json"; - if (index_path.ends_with(kJsonExtension) || index_path == kNeBuildFileJson) { - builder = std::make_unique(); + if (index_path.ends_with(kJsonExtension) || index_path == kNeBuildFileJson) { + builder = std::make_unique(); - /// report failed build to config. - if (!builder) { - config.has_failed(true); - return; - } - } else { - constexpr auto kTomlExtension = ".toml"; - builder = std::make_unique(); + /// report failed build to config. + if (!builder) { + config.has_failed(true); + return; + } + } else { + constexpr auto kTomlExtension = ".toml"; + builder = std::make_unique(); - if (!index_path.ends_with(kTomlExtension) && index_path != kNeBuildFileToml) { - NeBuild::Logger::info() << "error: file '" << index_path << "' is not a manifest file!" - << std::endl; - config.has_failed(true); - return; - } - } + if (!index_path.ends_with(kTomlExtension) && index_path != kNeBuildFileToml) { + NeBuild::Logger::info() + << "error: file '" << index_path << "' is not a manifest file!" << std::endl; + config.has_failed(true); + return; + } + } - std::string next_path; + std::string next_path; - if ((index_cpy + 1) < argc && argv[index_cpy + 1]) next_path = argv[index_cpy + 1]; + if ((index_cpy + 1) < argc && argv[index_cpy + 1]) next_path = argv[index_cpy + 1]; - if (next_path == "-build-system") { - NeBuild::Logger::info() << builder->BuildSystem() << std::endl; - std::exit(EXIT_SUCCESS); - } + if (next_path == "-build-system") { + NeBuild::Logger::info() << builder->BuildSystem() << std::endl; + std::exit(EXIT_SUCCESS); + } - NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; + NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; - config.path(index_path); + config.path(index_path); - if (builder && !builder->BuildTarget(config)) { - config.has_failed(true); - } - }, index_path}); + if (builder && !builder->BuildTarget(config)) { + config.has_failed(true); + } + }, + index_path}); } - for (auto& job : jobs) - job.join(); - + for (auto& job : jobs) job.join(); + // check for whether config is valid. if so return failure, or success. return !config ? EXIT_FAILURE : EXIT_SUCCESS; } -- cgit v1.2.3