* Be stricter in verifying store paths.

This commit is contained in:
Eelco Dolstra 2004-04-14 08:08:55 +00:00
parent 87bf541f23
commit a4d2b22c8c
3 changed files with 9 additions and 4 deletions

View file

@ -335,6 +335,7 @@ void ensurePath(const Path & path, PathSet pending)
StoreExpr storeExprFromPath(const Path & path, PathSet pending) StoreExpr storeExprFromPath(const Path & path, PathSet pending)
{ {
assertStorePath(path);
ensurePath(path, pending); ensurePath(path, pending);
ATerm t = ATreadFromNamedFile(path.c_str()); ATerm t = ATreadFromNamedFile(path.c_str());
if (!t) throw Error(format("cannot read aterm from `%1%'") % path); if (!t) throw Error(format("cannot read aterm from `%1%'") % path);

View file

@ -160,13 +160,14 @@ void copyPath(const Path & src, const Path & dst)
static bool isInStore(const Path & path) static bool isInStore(const Path & path)
{ {
return path[0] == '/' return path[0] == '/'
&& Path(path, 0, nixStore.size()) == nixStore && path.compare(0, nixStore.size(), nixStore) == 0
&& path.size() > nixStore.size() + 1 && path.size() >= nixStore.size() + 2
&& path[nixStore.size()] == '/'; && path[nixStore.size()] == '/'
&& path.find('/', nixStore.size() + 1) == Path::npos;
} }
static void assertStorePath(const Path & path) void assertStorePath(const Path & path)
{ {
if (!isInStore(path)) if (!isInStore(path))
throw Error(format("path `%1%' is not in the Nix store") % path); throw Error(format("path `%1%' is not in the Nix store") % path);

View file

@ -48,6 +48,9 @@ Paths querySubstitutes(const Path & srcPath);
/* Register the validity of a path. */ /* Register the validity of a path. */
void registerValidPath(const Transaction & txn, const Path & 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. */ /* Checks whether a path is valid. */
bool isValidPath(const Path & path); bool isValidPath(const Path & path);