diff options
author | Brad King <brad.king@kitware.com> | 2021-06-03 21:16:20 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-06-04 15:17:46 (GMT) |
commit | f2f62e295ad1254b7e3cdd5d78fa8afb0e86f1ce (patch) | |
tree | 8a716b65a2bb7245ad43e902ad0b6ffb21fe9fc7 | |
parent | c573f6b8b23593f46a08616b76325d3ce0175002 (diff) | |
download | Ninja-f2f62e295ad1254b7e3cdd5d78fa8afb0e86f1ce.zip Ninja-f2f62e295ad1254b7e3cdd5d78fa8afb0e86f1ce.tar.gz Ninja-f2f62e295ad1254b7e3cdd5d78fa8afb0e86f1ce.tar.bz2 |
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.
-rw-r--r-- | src/clean.cc | 5 | ||||
-rw-r--r-- | src/dyndep_parser.cc | 6 | ||||
-rw-r--r-- | src/manifest_parser.cc | 6 | ||||
-rw-r--r-- | src/ninja.cc | 8 |
4 files changed, 25 insertions, 0 deletions
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<EvalString>::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<EvalString>::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<EvalString>::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; |