about summary refs log tree commit diff
path: root/tvix/nix-compat/src/store_path/mod.rs
diff options
context:
space:
mode:
authorRyan Lahfa <tvl@lahfa.xyz>2023-08-19T17·00+0200
committerraitobezarius <tvl@lahfa.xyz>2023-08-20T19·34+0000
commit2d687e068abaa3ca876c33361a7b2befa2ccdf0e (patch)
treecc1e1bf75d6b548265b8cc0e21380d6c8adba5ab /tvix/nix-compat/src/store_path/mod.rs
parentd504b440c2ac420b6618b5caa5b08684575cf2ba (diff)
fix(tvix/nix-compat): disallow empty derivation names r/6495
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
Diffstat (limited to 'tvix/nix-compat/src/store_path/mod.rs')
-rw-r--r--tvix/nix-compat/src/store_path/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs
index 781e329325..0ed6b2ba07 100644
--- a/tvix/nix-compat/src/store_path/mod.rs
+++ b/tvix/nix-compat/src/store_path/mod.rs
@@ -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'-'