me
/
guix
Archived
1
0
Fork 0

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.
master
Ludovic Courtès 2020-12-03 09:44:22 +01:00
parent 5ff521452b
commit bfe4cdf88e
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 19 additions and 18 deletions

View File

@ -3040,27 +3040,28 @@ void SubstitutionGoal::finished()
if (!pathExists(destPath)) if (!pathExists(destPath))
throw SubstError(format("substitute did not produce path `%1%'") % destPath); throw SubstError(format("substitute did not produce path `%1%'") % destPath);
if (expectedHashStr == "")
throw SubstError(format("substituter did not communicate hash for `%1'") % storePath);
hash = hashPath(htSHA256, destPath); hash = hashPath(htSHA256, destPath);
/* Verify the expected hash we got from the substituer. */ /* Verify the expected hash we got from the substituer. */
if (expectedHashStr != "") { size_t n = expectedHashStr.find(':');
size_t n = expectedHashStr.find(':'); if (n == string::npos)
if (n == string::npos) throw Error(format("bad hash from substituter: %1%") % expectedHashStr);
throw Error(format("bad hash from substituter: %1%") % expectedHashStr); HashType hashType = parseHashType(string(expectedHashStr, 0, n));
HashType hashType = parseHashType(string(expectedHashStr, 0, n)); if (hashType == htUnknown)
if (hashType == htUnknown) throw Error(format("unknown hash algorithm in `%1%'") % expectedHashStr);
throw Error(format("unknown hash algorithm in `%1%'") % expectedHashStr); Hash expectedHash = parseHash16or32(hashType, string(expectedHashStr, n + 1));
Hash expectedHash = parseHash16or32(hashType, string(expectedHashStr, n + 1)); Hash actualHash = hashType == htSHA256 ? hash.first : hashPath(hashType, destPath).first;
Hash actualHash = hashType == htSHA256 ? hash.first : hashPath(hashType, destPath).first; if (expectedHash != actualHash) {
if (expectedHash != actualHash) { if (settings.printBuildTrace)
if (settings.printBuildTrace) printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%")
printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%") % storePath % "sha256"
% storePath % "sha256" % printHash16or32(expectedHash)
% printHash16or32(expectedHash) % printHash16or32(actualHash));
% printHash16or32(actualHash)); throw SubstError(format("hash mismatch for substituted item `%1%'") % storePath);
throw SubstError(format("hash mismatch for substituted item `%1%'") % storePath); }
}
}
} catch (SubstError & e) { } catch (SubstError & e) {