From b1e8fe7212618a61b78eeefa65075295fe2e40b2 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 17 Jan 2023 12:42:36 +0100 Subject: feat(tvix/derivation): check for other invalid output names This uses the exposed StorePath::validate_name method to check for other invalid output names (for which it would not be possible to construct a store path of). Change-Id: Ia3f65e19a07ef164f9f64013a5f37cbac99eb8e0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7855 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/derivation/src/validate.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tvix/derivation/src/validate.rs b/tvix/derivation/src/validate.rs index a214350901..c6cd2f8b9e 100644 --- a/tvix/derivation/src/validate.rs +++ b/tvix/derivation/src/validate.rs @@ -20,8 +20,11 @@ impl Derivation { // meaning. // // Other output names that don't match the name restrictions from - // [StorePath] will fail output path calculation. - if output_name.is_empty() || output_name == "drv" { + // [StorePath] will fail the [StorePath::validate_name] check. + if output_name.is_empty() + || output_name == "drv" + || StorePath::validate_name(&output_name).is_err() + { return Err(DerivationError::InvalidOutputName(output_name.to_string())); } @@ -73,10 +76,12 @@ impl Derivation { // `drvPath` key (which already exists) and has a different // meaning. // - // Other output names that don't match the name restrictions - // from [StorePath] can't be constructed with this library, but - // are not explicitly checked here (yet). - if output_name.is_empty() || output_name == "drv" { + // Other output names that don't match the name restrictions from + // [StorePath] will fail the [StorePath::validate_name] check. + if output_name.is_empty() + || output_name == "drv" + || StorePath::validate_name(&output_name).is_err() + { return Err(DerivationError::InvalidInputDerivationOutputName( input_derivation_path.to_string(), output_name.to_string(), -- cgit 1.4.1