diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-05-15T16·44+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-05-15T16·47+0200 |
commit | c05d9ae7a5f72a6575130cf92fb54e3f90d1927d (patch) | |
tree | 76f0de541e7d151cd62929969c31f73966dead9c /src/libexpr | |
parent | a2d92bb20e82a0957067ede60e91fab256948b41 (diff) |
Disallow outputHash being null or an empty string
Fixes #1384.
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 615cc8138433..cc23827a17a6 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -534,7 +534,8 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * PathSet context; - string outputHash, outputHashAlgo; + std::experimental::optional<std::string> outputHash; + std::string outputHashAlgo; bool outputHashRecursive = false; StringSet outputs; @@ -703,7 +704,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * throw EvalError(format("derivation names are not allowed to end in ‘%1%’, at %2%") % drvExtension % posDrvName); - if (outputHash != "") { + if (outputHash) { /* Handle fixed-output derivations. */ if (outputs.size() != 1 || *(outputs.begin()) != "out") throw Error(format("multiple outputs are not supported in fixed-output derivations, at %1%") % posDrvName); @@ -711,13 +712,13 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * HashType ht = parseHashType(outputHashAlgo); if (ht == htUnknown) throw EvalError(format("unknown hash algorithm ‘%1%’, at %2%") % outputHashAlgo % posDrvName); - Hash h = parseHash16or32(ht, outputHash); + Hash h = parseHash16or32(ht, *outputHash); outputHash = printHash(h); if (outputHashRecursive) outputHashAlgo = "r:" + outputHashAlgo; Path outPath = state.store->makeFixedOutputPath(outputHashRecursive, h, drvName); drv.env["out"] = outPath; - drv.outputs["out"] = DerivationOutput(outPath, outputHashAlgo, outputHash); + drv.outputs["out"] = DerivationOutput(outPath, outputHashAlgo, *outputHash); } else { |