summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-04-14 08:08:55 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-04-14 08:08:55 +0000
commita4d2b22c8ca5064f1da614914c7ea336eedd65c4 (patch)
tree6ba789f13a5a70011a0efd8aa67d132eb88431b4 /src/libstore
parent87bf541f23723f6a8c7f05c89984c5df0c450ec2 (diff)
downloadguix-a4d2b22c8ca5064f1da614914c7ea336eedd65c4.tar.gz
* Be stricter in verifying store paths.
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 5d3771b233..69c9103d9e 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 d85b0608f4..a89e4ed89f 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 143cad8dbe..571d498c36 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);