diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-11-26 20:12:15 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-11-26 20:12:15 +0100 |
commit | c13193017fdcb910627698e343c2df4183d91f8f (patch) | |
tree | 9f2d87cbc214490f1d7e3c15912e8f863de3176a /src/libstore/store-api.cc | |
parent | 89db9353d7cc5aaf360c48d17aeb0e9ddd940451 (diff) |
Disallow empty store path names
Fixes #3239.
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 54430d3ba..0758907e7 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -90,17 +90,22 @@ void checkStoreName(const string & name) "Path names are alphanumeric and can include the symbols %1% " "and must not begin with a period. " "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; + if (name.empty()) + throw Error(baseError % "it is an empty string"); + /* Disallow names starting with a dot for possible security 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"); + /* Disallow names longer than 211 characters. ext4’s max is 256, but we need extra space for the hash and .chroot extensions. */ if (name.length() > 211) throw Error(baseError % "name must be less than 212 characters"); + for (auto & i : name) if (!((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z') || |