diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-08-27 10:42:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-08-27 10:42:25 +0200 |
commit | 85a97e180e5f68d62821bfb9c7cad212737f2f9c (patch) | |
tree | 5a1152ac7d196c487040d2e3dfbffd337ff2c9b7 | |
parent | 5182e007931b2ebf034d1a9ed42737ed30b2ac13 (diff) |
Handle invalid scope paths specified in buildfile (GH issue #396)
-rw-r--r-- | libbuild2/parser.cxx | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 8af5804..e417d39 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1757,11 +1757,18 @@ namespace build2 } else { - // Note that p cannot point to the last character since then it - // would have been a directory, not a simple name. - // - d = dir_path (ns[0].value, 0, p + 1); - ns[0].value.erase (0, p + 1); + try + { + // Note that p cannot point to the last character since then it + // would have been a directory, not a simple name. + // + d = dir_path (ns[0].value, 0, p + 1); + ns[0].value.erase (0, p + 1); + } + catch (const invalid_path& e) + { + fail (nloc) << "invalid scope path '" << e.path << "'"; + } } } @@ -8802,15 +8809,22 @@ namespace build2 (p = path_traits::rfind_separator (ns[0].value)) != string::npos) { - // Note that p cannot point to the last character since - // then it would have been a directory, not a simple name. - // - string& s (ns[0].value); - - name = string (s, p + 1); - s.resize (p + 1); - qual.push_back (name_type (dir_path (move (s)))); - qual.back ().pair = '/'; + try + { + // Note that p cannot point to the last character since + // then it would have been a directory, not a simple name. + // + string& s (ns[0].value); + + name = string (s, p + 1); + s.resize (p + 1); + qual.push_back (name_type (dir_path (move (s)))); + qual.back ().pair = '/'; + } + catch (const invalid_path& e) + { + fail (loc) << "invalid scope path '" << e.path << "'"; + } } else name = move (ns[n - 1].value); |