summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-12-03 09:44:22 +0100
committerLudovic Courtès <ludo@gnu.org>2020-12-08 22:30:08 +0100
commitbfe4cdf88ee3e88910d22291a4c745462f2d6417 (patch)
tree215d220b02cae9f03b1c9a33782ff7f67945e76b
parent5ff521452b9ec2aae9ed8e4bb7bdc250a581f203 (diff)
daemon: Raise an error if substituter doesn't send the expected hash.
It was already impossible in practice for 'expectedHashStr' to be empty if 'status' == "success". * nix/libstore/build.cc (SubstitutionGoal::finished): Throw 'SubstError' when 'expectedHashStr' is empty.
-rw-r--r--nix/libstore/build.cc37
1 files changed, 19 insertions, 18 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 6cfe7aba7e6..b5551b87aee 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -3040,27 +3040,28 @@ void SubstitutionGoal::finished()
3040 if (!pathExists(destPath)) 3040 if (!pathExists(destPath))
3041 throw SubstError(format("substitute did not produce path `%1%'") % destPath); 3041 throw SubstError(format("substitute did not produce path `%1%'") % destPath);
3042 3042
3043 if (expectedHashStr == "")
3044 throw SubstError(format("substituter did not communicate hash for `%1'") % storePath);
3045
3043 hash = hashPath(htSHA256, destPath); 3046 hash = hashPath(htSHA256, destPath);
3044 3047
3045 /* Verify the expected hash we got from the substituer. */ 3048 /* Verify the expected hash we got from the substituer. */
3046 if (expectedHashStr != "") { 3049 size_t n = expectedHashStr.find(':');
3047 size_t n = expectedHashStr.find(':'); 3050 if (n == string::npos)
3048 if (n == string::npos) 3051 throw Error(format("bad hash from substituter: %1%") % expectedHashStr);
3049 throw Error(format("bad hash from substituter: %1%") % expectedHashStr); 3052 HashType hashType = parseHashType(string(expectedHashStr, 0, n));
3050 HashType hashType = parseHashType(string(expectedHashStr, 0, n)); 3053 if (hashType == htUnknown)
3051 if (hashType == htUnknown) 3054 throw Error(format("unknown hash algorithm in `%1%'") % expectedHashStr);
3052 throw Error(format("unknown hash algorithm in `%1%'") % expectedHashStr); 3055 Hash expectedHash = parseHash16or32(hashType, string(expectedHashStr, n + 1));
3053 Hash expectedHash = parseHash16or32(hashType, string(expectedHashStr, n + 1)); 3056 Hash actualHash = hashType == htSHA256 ? hash.first : hashPath(hashType, destPath).first;
3054 Hash actualHash = hashType == htSHA256 ? hash.first : hashPath(hashType, destPath).first; 3057 if (expectedHash != actualHash) {
3055 if (expectedHash != actualHash) { 3058 if (settings.printBuildTrace)
3056 if (settings.printBuildTrace) 3059 printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%")
3057 printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%") 3060 % storePath % "sha256"
3058 % storePath % "sha256" 3061 % printHash16or32(expectedHash)
3059 % printHash16or32(expectedHash) 3062 % printHash16or32(actualHash));
3060 % printHash16or32(actualHash)); 3063 throw SubstError(format("hash mismatch for substituted item `%1%'") % storePath);
3061 throw SubstError(format("hash mismatch for substituted item `%1%'") % storePath); 3064 }
3062 }
3063 }
3064 3065
3065 } catch (SubstError & e) { 3066 } catch (SubstError & e) {
3066 3067