Disallow empty store path names

Fixes #3239.
This commit is contained in:
Eelco Dolstra 2019-11-26 20:12:15 +01:00
parent 89db9353d7
commit c13193017f
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 11 additions and 4 deletions

View file

@ -585,6 +585,8 @@ void LocalStore::checkDerivationOutputs(const Path & drvPath, const Derivation &
uint64_t LocalStore::addValidPath(State & state, uint64_t LocalStore::addValidPath(State & state,
const ValidPathInfo & info, bool checkOutputs) const ValidPathInfo & info, bool checkOutputs)
{ {
checkStoreName(storePathToName(info.path));
if (info.ca != "" && !info.isContentAddressed(*this)) if (info.ca != "" && !info.isContentAddressed(*this))
throw Error("cannot add path '%s' to the Nix store because it claims to be content-addressed but isn't", info.path); throw Error("cannot add path '%s' to the Nix store because it claims to be content-addressed but isn't", info.path);

View file

@ -90,17 +90,22 @@ void checkStoreName(const string & name)
"Path names are alphanumeric and can include the symbols %1% " "Path names are alphanumeric and can include the symbols %1% "
"and must not begin with a period. " "and must not begin with a period. "
"Note: If '%2%' is a source file and you cannot rename it on " "Note: If '%2%' is a source file and you cannot rename it on "
"disk, builtins.path { name = ... } can be used to give it an " "disk, 'builtins.path { name = ... }' can be used to give it an "
"alternative name.") % validChars % name; "alternative name.") % validChars % name;
if (name.empty())
throw Error(baseError % "it is an empty string");
/* Disallow names starting with a dot for possible security /* Disallow names starting with a dot for possible security
reasons (e.g., "." and ".."). */ reasons (e.g., "." and ".."). */
if (string(name, 0, 1) == ".") if (name[0] == '.')
throw Error(baseError % "it is illegal to start the name with a period"); throw Error(baseError % "it is illegal to start the name with a period");
/* Disallow names longer than 211 characters. ext4s max is 256, /* Disallow names longer than 211 characters. ext4s max is 256,
but we need extra space for the hash and .chroot extensions. */ but we need extra space for the hash and .chroot extensions. */
if (name.length() > 211) if (name.length() > 211)
throw Error(baseError % "name must be less than 212 characters"); throw Error(baseError % "name must be less than 212 characters");
for (auto & i : name) for (auto & i : name)
if (!((i >= 'A' && i <= 'Z') || if (!((i >= 'A' && i <= 'Z') ||
(i >= 'a' && i <= 'z') || (i >= 'a' && i <= 'z') ||

View file

@ -4,9 +4,9 @@ clearStore
max=500 max=500
reference=$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa reference=$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bla
touch $reference touch $reference
(echo $reference && echo && echo 0) | nix-store --register-validity (echo $reference && echo && echo 0) | nix-store --register-validity
echo "making registration..." echo "making registration..."