aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2023-10-04 16:50:24 +0000
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2023-10-08 12:21:18 +0000
commit82040664e4cb686011aaff8acf101d1ac33f960b (patch)
tree279ae3d227f9a41747859d2c475523d67294ffe1 /src
parentf5f4de6a550327b4b1a06123c2e450f1b92c73b6 (diff)
StorePath: reject names starting with '.'
This has been the behaviour before Nix 2.4. It was dropped in a rewrite in 759947bf72c134592f0ce23d385e48095bd0a301, allowing the creation of store paths that aren't considered valid by older Nix versions or other Nix tooling. Nix 2.4 didn't ship in NixOS until 22.05, and stdenv.mkDerivation in nixpkgs drops leading periods since April 2022, so it's unlikely anyone is relying on the current lax behaviour. Closes #9091. Change-Id: I4a57bd9899e1b0dba56870ae5a1b680918a18ce9 (cherry picked from commit 24bda0c7b381e1a017023c6f7cb9661fae8560bd)
Diffstat (limited to 'src')
-rw-r--r--src/libstore/path-regex.hh2
-rw-r--r--src/libstore/path.cc2
-rw-r--r--src/libstore/tests/path.cc9
3 files changed, 10 insertions, 3 deletions
diff --git a/src/libstore/path-regex.hh b/src/libstore/path-regex.hh
index 4f8dc4c1f..a44e6a2eb 100644
--- a/src/libstore/path-regex.hh
+++ b/src/libstore/path-regex.hh
@@ -3,6 +3,6 @@
namespace nix {
-static constexpr std::string_view nameRegexStr = R"([0-9a-zA-Z\+\-\._\?=]+)";
+static constexpr std::string_view nameRegexStr = R"([0-9a-zA-Z\+\-_\?=][0-9a-zA-Z\+\-\._\?=]*)";
}
diff --git a/src/libstore/path.cc b/src/libstore/path.cc
index 552e83114..3c6b9fc10 100644
--- a/src/libstore/path.cc
+++ b/src/libstore/path.cc
@@ -11,6 +11,8 @@ static void checkName(std::string_view path, std::string_view name)
if (name.size() > StorePath::MaxPathLen)
throw BadStorePath("store path '%s' has a name longer than %d characters",
path, StorePath::MaxPathLen);
+ if (name[0] == '.')
+ throw BadStorePath("store path '%s' starts with illegal character '.'", path);
// See nameRegexStr for the definition
for (auto c : name)
if (!((c >= '0' && c <= '9')
diff --git a/src/libstore/tests/path.cc b/src/libstore/tests/path.cc
index efa35ef2b..5a84d646c 100644
--- a/src/libstore/tests/path.cc
+++ b/src/libstore/tests/path.cc
@@ -39,6 +39,7 @@ TEST_DONT_PARSE(double_star, "**")
TEST_DONT_PARSE(star_first, "*,foo")
TEST_DONT_PARSE(star_second, "foo,*")
TEST_DONT_PARSE(bang, "foo!o")
+TEST_DONT_PARSE(dotfile, ".gitignore")
#undef TEST_DONT_PARSE
@@ -101,8 +102,12 @@ Gen<StorePathName> Arbitrary<StorePathName>::arbitrary()
pre += '-';
break;
case 64:
- pre += '.';
- break;
+ // names aren't permitted to start with a period,
+ // so just fall through to the next case here
+ if (c != 0) {
+ pre += '.';
+ break;
+ }
case 65:
pre += '_';
break;