fix(tvix/nix-compat): disallow empty derivation names

Yes:

```
$ nix-build -E 'derivation { name = ""; builder = "/bin/sh"; system = "x86_64-linux"; }'
error: store path 'nr7i5pf18hw2zg487vkdyrbasdqylfcj-' has an empty name
```

Change-Id: I552f9ed1c1fe3bfceca18ca9b8e13d4b06dc6ff7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9108
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Ryan Lahfa 2023-08-19 19:00:11 +02:00 committed by raitobezarius
parent d504b440c2
commit 2d687e068a

View file

@ -151,6 +151,16 @@ impl StorePath {
/// Checks a given &[u8] to match the restrictions for store path names, and
/// returns the name as string if successful.
pub(crate) fn validate_name(s: &[u8]) -> Result<String, Error> {
// Empty names are not allowed.
if s.is_empty() {
return Err(Error::InvalidLength());
}
// First character cannot be a period
if s[0] == b'.' {
return Err(Error::InvalidName(s.to_vec(), 0));
}
for (i, c) in s.iter().enumerate() {
if c.is_ascii_alphanumeric()
|| *c == b'-'