about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/normalise.cc1
-rw-r--r--src/libstore/store.cc9
-rw-r--r--src/libstore/store.hh3
3 files changed, 9 insertions, 4 deletions
diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc
index 5d3771b23343..69c9103d9e45 100644
--- a/src/libstore/normalise.cc
+++ b/src/libstore/normalise.cc
@@ -335,6 +335,7 @@ void ensurePath(const Path & path, PathSet pending)
 
 StoreExpr storeExprFromPath(const Path & path, PathSet pending)
 {
+    assertStorePath(path);
     ensurePath(path, pending);
     ATerm t = ATreadFromNamedFile(path.c_str());
     if (!t) throw Error(format("cannot read aterm from `%1%'") % path);
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index d85b0608f409..a89e4ed89fa7 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -160,13 +160,14 @@ void copyPath(const Path & src, const Path & dst)
 static bool isInStore(const Path & path)
 {
     return path[0] == '/'
-        && Path(path, 0, nixStore.size()) == nixStore
-        && path.size() > nixStore.size() + 1
-        && path[nixStore.size()] == '/';
+        && path.compare(0, nixStore.size(), nixStore) == 0
+        && path.size() >= nixStore.size() + 2
+        && path[nixStore.size()] == '/'
+        && path.find('/', nixStore.size() + 1) == Path::npos;
 }
 
 
-static void assertStorePath(const Path & path)
+void assertStorePath(const Path & path)
 {
     if (!isInStore(path))
         throw Error(format("path `%1%' is not in the Nix store") % path);
diff --git a/src/libstore/store.hh b/src/libstore/store.hh
index 143cad8dbe7a..571d498c362d 100644
--- a/src/libstore/store.hh
+++ b/src/libstore/store.hh
@@ -48,6 +48,9 @@ Paths querySubstitutes(const Path & srcPath);
 /* Register the validity of a path. */
 void registerValidPath(const Transaction & txn, const Path & path);
 
+/* Throw an exception if `path' is not directly in the Nix store. */
+void assertStorePath(const Path & path);
+
 /* Checks whether a path is valid. */ 
 bool isValidPath(const Path & path);