StorePath: reject names starting with '.'
This has been the behaviour before Nix 2.4. It was dropped in a rewrite in759947bf72
, 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)
This commit is contained in:
parent
f5f4de6a55
commit
82040664e4
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
namespace nix {
|
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\+\-\._\?=]*)";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ static void checkName(std::string_view path, std::string_view name)
|
||||||
if (name.size() > StorePath::MaxPathLen)
|
if (name.size() > StorePath::MaxPathLen)
|
||||||
throw BadStorePath("store path '%s' has a name longer than %d characters",
|
throw BadStorePath("store path '%s' has a name longer than %d characters",
|
||||||
path, StorePath::MaxPathLen);
|
path, StorePath::MaxPathLen);
|
||||||
|
if (name[0] == '.')
|
||||||
|
throw BadStorePath("store path '%s' starts with illegal character '.'", path);
|
||||||
// See nameRegexStr for the definition
|
// See nameRegexStr for the definition
|
||||||
for (auto c : name)
|
for (auto c : name)
|
||||||
if (!((c >= '0' && c <= '9')
|
if (!((c >= '0' && c <= '9')
|
||||||
|
|
|
@ -39,6 +39,7 @@ TEST_DONT_PARSE(double_star, "**")
|
||||||
TEST_DONT_PARSE(star_first, "*,foo")
|
TEST_DONT_PARSE(star_first, "*,foo")
|
||||||
TEST_DONT_PARSE(star_second, "foo,*")
|
TEST_DONT_PARSE(star_second, "foo,*")
|
||||||
TEST_DONT_PARSE(bang, "foo!o")
|
TEST_DONT_PARSE(bang, "foo!o")
|
||||||
|
TEST_DONT_PARSE(dotfile, ".gitignore")
|
||||||
|
|
||||||
#undef TEST_DONT_PARSE
|
#undef TEST_DONT_PARSE
|
||||||
|
|
||||||
|
@ -101,8 +102,12 @@ Gen<StorePathName> Arbitrary<StorePathName>::arbitrary()
|
||||||
pre += '-';
|
pre += '-';
|
||||||
break;
|
break;
|
||||||
case 64:
|
case 64:
|
||||||
|
// names aren't permitted to start with a period,
|
||||||
|
// so just fall through to the next case here
|
||||||
|
if (c != 0) {
|
||||||
pre += '.';
|
pre += '.';
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 65:
|
case 65:
|
||||||
pre += '_';
|
pre += '_';
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue