From f2f62e295ad1254b7e3cdd5d78fa8afb0e86f1ce Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 3 Jun 2021 17:16:20 -0400 Subject: Add explicit "empty path" errors before calling CanonicalizePath Update call sites that might have empty paths to explicitly check for them before calling CanonicalizePath. Note that the depfile parser ensures all parsed outs and deps are non-empty. --- src/clean.cc | 5 +++++ src/dyndep_parser.cc | 6 ++++++ src/manifest_parser.cc | 6 ++++++ src/ninja.cc | 8 ++++++++ 4 files changed, 25 insertions(+) diff --git a/src/clean.cc b/src/clean.cc index 3e57437..1e97182 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -189,6 +189,11 @@ int Cleaner::CleanTargets(int target_count, char* targets[]) { LoadDyndeps(); for (int i = 0; i < target_count; ++i) { string target_name = targets[i]; + if (target_name.empty()) { + Error("failed to canonicalize '': empty path"); + status_ = 1; + continue; + } uint64_t slash_bits; string err; if (!CanonicalizePath(&target_name, &slash_bits, &err)) { diff --git a/src/dyndep_parser.cc b/src/dyndep_parser.cc index 56da16f..45d1c31 100644 --- a/src/dyndep_parser.cc +++ b/src/dyndep_parser.cc @@ -115,6 +115,8 @@ bool DyndepParser::ParseEdge(string* err) { return lexer_.Error("expected path", err); string path = out0.Evaluate(&env_); + if (path.empty()) + return lexer_.Error("empty path", err); string path_err; uint64_t slash_bits; if (!CanonicalizePath(&path, &slash_bits, &path_err)) @@ -202,6 +204,8 @@ bool DyndepParser::ParseEdge(string* err) { dyndeps->implicit_inputs_.reserve(ins.size()); for (vector::iterator i = ins.begin(); i != ins.end(); ++i) { string path = i->Evaluate(&env_); + if (path.empty()) + return lexer_.Error("empty path", err); string path_err; uint64_t slash_bits; if (!CanonicalizePath(&path, &slash_bits, &path_err)) @@ -213,6 +217,8 @@ bool DyndepParser::ParseEdge(string* err) { dyndeps->implicit_outputs_.reserve(outs.size()); for (vector::iterator i = outs.begin(); i != outs.end(); ++i) { string path = i->Evaluate(&env_); + if (path.empty()) + return lexer_.Error("empty path", err); string path_err; uint64_t slash_bits; if (!CanonicalizePath(&path, &slash_bits, &path_err)) diff --git a/src/manifest_parser.cc b/src/manifest_parser.cc index f77109f..8f0528a 100644 --- a/src/manifest_parser.cc +++ b/src/manifest_parser.cc @@ -190,6 +190,8 @@ bool ManifestParser::ParseDefault(string* err) { do { string path = eval.Evaluate(env_); + if (path.empty()) + return lexer_.Error("empty path", err); string path_err; uint64_t slash_bits; // Unused because this only does lookup. if (!CanonicalizePath(&path, &slash_bits, &path_err)) @@ -317,6 +319,8 @@ bool ManifestParser::ParseEdge(string* err) { edge->outputs_.reserve(outs.size()); for (size_t i = 0, e = outs.size(); i != e; ++i) { string path = outs[i].Evaluate(env); + if (path.empty()) + return lexer_.Error("empty path", err); string path_err; uint64_t slash_bits; if (!CanonicalizePath(&path, &slash_bits, &path_err)) @@ -349,6 +353,8 @@ bool ManifestParser::ParseEdge(string* err) { edge->inputs_.reserve(ins.size()); for (vector::iterator i = ins.begin(); i != ins.end(); ++i) { string path = i->Evaluate(env); + if (path.empty()) + return lexer_.Error("empty path", err); string path_err; uint64_t slash_bits; if (!CanonicalizePath(&path, &slash_bits, &path_err)) diff --git a/src/ninja.cc b/src/ninja.cc index c7182df..d55290c 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -252,6 +252,10 @@ int GuessParallelism() { bool NinjaMain::RebuildManifest(const char* input_file, string* err, Status* status) { string path = input_file; + if (path.empty()) { + *err = "empty path"; + return false; + } uint64_t slash_bits; // Unused because this path is only used for lookup. if (!CanonicalizePath(&path, &slash_bits, err)) return false; @@ -284,6 +288,10 @@ bool NinjaMain::RebuildManifest(const char* input_file, string* err, Node* NinjaMain::CollectTarget(const char* cpath, string* err) { string path = cpath; + if (path.empty()) { + *err = "empty path"; + return NULL; + } uint64_t slash_bits; if (!CanonicalizePath(&path, &slash_bits, err)) return NULL; -- cgit v0.12