about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-08-24T11·46+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-08-24T11·46+0000
commit9994c1dd9fe19a3bb8f7bbddbcd5622c9c30d85b (patch)
treeb14ab3baac2044bba0ad6f4d538cfccae51dbf18 /src/libexpr/primops.cc
parent8f58733ef16bdefe3cdb004bea986b6a0b893331 (diff)
* Validate derivation names. In particular don't allow spaces.
* Drop support for the outPath attribute in derivations.

Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index ad1c02247e3f..6588922c26b9 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -181,7 +181,6 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
     ne.type = StoreExpr::neDerivation;
 
     string drvName;
-    Path outPath;
     Hash outHash;
     bool outHashGiven = false;
 
@@ -217,7 +216,6 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
             if (key == "builder") ne.derivation.builder = s;
             else if (key == "system") ne.derivation.platform = s;
             else if (key == "name") drvName = s;
-            else if (key == "outPath") outPath = s;
             else if (key == "id") { 
                 outHash = parseHash(s);
                 outHashGiven = true;
@@ -232,14 +230,27 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
         throw Error("required attribute `system' missing");
     if (drvName == "")
         throw Error("required attribute `name' missing");
+
+    /* Check the derivation name.  It shouldn't contain whitespace,
+       but we are conservative here: we check whether only
+       alphanumerics and some other characters appear. */
+    string validChars = "+-._?=";
+    for (string::iterator i = drvName.begin(); i != drvName.end(); ++i)
+        if (!((*i >= 'A' && *i <= 'Z') ||
+              (*i >= 'a' && *i <= 'z') ||
+              (*i >= '0' && *i <= '9') ||
+              validChars.find(*i) != string::npos))
+        {
+            throw Error(format("invalid character `%1%' in derivation name `%2%'")
+                % *i % drvName);
+        }
         
-    /* Determine the output path. */
+    /* Determine the output path by hashing the Nix expression with no
+       outputs to produce a unique but deterministic path name for
+       this derivation. */
     if (!outHashGiven) outHash = hashDerivation(state, ne);
-    if (outPath == "")
-        /* Hash the Nix expression with no outputs to produce a
-           unique but deterministic path name for this derivation. */
-        outPath = canonPath(nixStore + "/" + 
-            ((string) outHash).c_str() + "-" + drvName);
+    Path outPath = canonPath(nixStore + "/" + 
+        ((string) outHash).c_str() + "-" + drvName);
     ne.derivation.env["out"] = outPath;
     ne.derivation.outputs.insert(outPath);