aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-01-14 13:51:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-01-14 13:51:31 +0200
commit28fb279aba3af8bf1a57a9e36b2b183ef68c5454 (patch)
tree1f8701bbd996b347ecbc024865159c9df457fec2
parent53e7e314e89f7e6262a8b169ce4c5aa872b8ceee (diff)
Diagnose target names with multiple trailing slashes as invalid
-rw-r--r--build2/b.cxx2
-rw-r--r--build2/scope.cxx10
-rw-r--r--build2/scope.hxx10
-rw-r--r--build2/target.cxx2
4 files changed, 17 insertions, 7 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index bb7ec41..bc19bfd 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 feac2fe..7ea4f42 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 7bdddde..a18794f 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<const target_type*, optional<string>>
find_target_type (name&, const location&) const;
diff --git a/build2/target.cxx b/build2/target.cxx
index e70a386..1c8b85f 100644
--- a/build2/target.cxx
+++ b/build2/target.cxx
@@ -220,6 +220,8 @@ namespace build2
optional<string> 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