diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-10-31 14:01:11 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-10-31 17:41:19 +0300 |
commit | 11efae6173b3a84b1cdc4836b5b22a1ee77eb084 (patch) | |
tree | 3026aaa5b2258160779c8dcb4e68527a948e842e /libbuild2 | |
parent | 328496a6f5bee5ec99f4d5de057cabed26bde7a9 (diff) |
Fix crashing on unhandled invalid_path thrown by parser::parse_include()
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/parser.cxx | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 6e15cf3..ca4f8d5 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1439,7 +1439,15 @@ namespace build2 else { a = path::traits_type::is_separator (n.value.back ()); - p /= path (move (n.value)); + + try + { + p /= path (move (n.value)); + } + catch (const invalid_path& e) + { + fail (l) << "invalid include path '" << e.path << "'"; + } } if (a) @@ -1458,26 +1466,37 @@ namespace build2 // dir_path out_base; - if (p.relative ()) + try { - out_base = scope_->out_path () / p.directory (); - out_base.normalize (); + if (p.relative ()) + { + out_base = scope_->out_path () / p.directory (); + out_base.normalize (); + } + else + { + p.normalize (); + + // Make sure the path is in this project. Include is only meant + // to be used for intra-project inclusion (plus amalgamation). + // + bool in_out (false); + if (!p.sub (root_->src_path ()) && + !(in_out = p.sub (root_->out_path ()))) + fail (l) << "out of project include " << p; + + out_base = in_out + ? p.directory () + : out_src (p.directory (), *root_); + } } - else + catch (const invalid_path&) { - p.normalize (); - - // Make sure the path is in this project. Include is only meant - // to be used for intra-project inclusion (plus amalgamation). + // The failure reason can only be the specified 'go past the root' + // path. Let's print the original path. // - bool in_out (false); - if (!p.sub (root_->src_path ()) && - !(in_out = p.sub (root_->out_path ()))) - fail (l) << "out of project include " << p; - - out_base = in_out - ? p.directory () - : out_src (p.directory (), *root_); + fail (l) << "invalid include path '" << (a ? p.directory () : p) + << "'"; } // Switch the scope. Note that we need to do this before figuring |