From 28fb279aba3af8bf1a57a9e36b2b183ef68c5454 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 Jan 2019 13:51:31 +0200 Subject: Diagnose target names with multiple trailing slashes as invalid --- build2/b.cxx | 2 +- build2/scope.cxx | 10 +++++++++- build2/scope.hxx | 10 +++++----- build2/target.cxx | 2 ++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/build2/b.cxx b/build2/b.cxx index bb7ec418..bc19bfde 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -630,7 +630,7 @@ main (int argc, char* argv[]) } } - // Expose eraly so can be used during bootstrap (with the same + // Expose early so can be used during bootstrap (with the same // limitations as for pre-processing). // global_scope->rw ().assign (var_build_meta_operation) = mname; diff --git a/build2/scope.cxx b/build2/scope.cxx index feac2feb..7ea4f427 100644 --- a/build2/scope.cxx +++ b/build2/scope.cxx @@ -667,7 +667,15 @@ namespace build2 fail (loc) << "invalid path '" << e.path << "'"; } - v.erase (0, p + 1); + // This is probably too general of a place to ignore multiple trailing + // slashes and treat it as a directory (e.g., we don't want to + // encourage this sloppiness in buildfiles). We could, however, do it + // for certain contexts, such as buildspec. Maybe a lax flag? + // + if (++p == v.size ()) + fail (loc) << "invalid name '" << v << "'"; + + v.erase (0, p); } // Extract the extension. diff --git a/build2/scope.hxx b/build2/scope.hxx index 7bdddde2..a18794f2 100644 --- a/build2/scope.hxx +++ b/build2/scope.hxx @@ -218,11 +218,11 @@ namespace build2 const target_type* find_target_type (const string&, const scope** = nullptr) const; - // Given a name, figure out its type, taking into account extensions, - // special names (e.g., '.' and '..'), or anything else that might be - // relevant. Process the name (in place) by extracting (and returning) - // extension, adjusting dir/leaf, etc., (note that the dir is not - // necessarily normalized). Return NULL if not found. + // Given a target name, figure out its type, taking into account + // extensions, special names (e.g., '.' and '..'), or anything else that + // might be relevant. Process the name (in place) by extracting (and + // returning) extension, adjusting dir/leaf, etc., (note that the dir is + // not necessarily normalized). Return NULL if not found. // pair> find_target_type (name&, const location&) const; diff --git a/build2/target.cxx b/build2/target.cxx index e70a386e..1c8b85f6 100644 --- a/build2/target.cxx +++ b/build2/target.cxx @@ -220,6 +220,8 @@ namespace build2 optional target:: split_name (string& v, const location& loc) { + assert (!v.empty ()); + // We treat a single trailing dot as "specified no extension", double dots // as a single trailing dot (that is, an escape sequence which can be // repeated any number of times; in such cases we naturally assume there -- cgit