Merge pull request #9122 from NixOS/backport-9095-to-2.18-maintenance

[Backport 2.18-maintenance] StorePath: reject names starting with '.'
This commit is contained in:
John Ericson 2023-10-09 10:27:51 -04:00 committed by GitHub
commit 78fd621397
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View file

@ -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\+\-\._\?=]*)";
} }

View file

@ -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')

View file

@ -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:
pre += '.'; // names aren't permitted to start with a period,
break; // so just fall through to the next case here
if (c != 0) {
pre += '.';
break;
}
case 65: case 65:
pre += '_'; pre += '_';
break; break;