From 85a97e180e5f68d62821bfb9c7cad212737f2f9c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 27 Aug 2024 10:42:25 +0200 Subject: Handle invalid scope paths specified in buildfile (GH issue #396) --- libbuild2/parser.cxx | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'libbuild2') 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); -- cgit v1.1