unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 45018@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#45018] [PATCH v2 6/6] daemon: Raise an error if substituter doesn't send the expected hash.
Date: Sun,  6 Dec 2020 23:04:15 +0100	[thread overview]
Message-ID: <20201206220415.23279-7-ludo@gnu.org> (raw)
In-Reply-To: <20201206220415.23279-1-ludo@gnu.org>

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.
---
 nix/libstore/build.cc | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 6cfe7aba7e..b5551b87ae 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -3040,27 +3040,28 @@ void SubstitutionGoal::finished()
         if (!pathExists(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);
 
         /* Verify the expected hash we got from the substituer. */
-        if (expectedHashStr != "") {
-            size_t n = expectedHashStr.find(':');
-            if (n == string::npos)
-                throw Error(format("bad hash from substituter: %1%") % expectedHashStr);
-            HashType hashType = parseHashType(string(expectedHashStr, 0, n));
-            if (hashType == htUnknown)
-                throw Error(format("unknown hash algorithm in `%1%'") % expectedHashStr);
-            Hash expectedHash = parseHash16or32(hashType, string(expectedHashStr, n + 1));
-            Hash actualHash = hashType == htSHA256 ? hash.first : hashPath(hashType, destPath).first;
-            if (expectedHash != actualHash) {
-		if (settings.printBuildTrace)
-		    printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%")
-			     % storePath % "sha256"
-			     % printHash16or32(expectedHash)
-			     % printHash16or32(actualHash));
-                throw SubstError(format("hash mismatch for substituted item `%1%'") % storePath);
-	    }
-        }
+	size_t n = expectedHashStr.find(':');
+	if (n == string::npos)
+	    throw Error(format("bad hash from substituter: %1%") % expectedHashStr);
+	HashType hashType = parseHashType(string(expectedHashStr, 0, n));
+	if (hashType == htUnknown)
+	    throw Error(format("unknown hash algorithm in `%1%'") % expectedHashStr);
+	Hash expectedHash = parseHash16or32(hashType, string(expectedHashStr, n + 1));
+	Hash actualHash = hashType == htSHA256 ? hash.first : hashPath(hashType, destPath).first;
+	if (expectedHash != actualHash) {
+	    if (settings.printBuildTrace)
+		printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%")
+			 % storePath % "sha256"
+			 % printHash16or32(expectedHash)
+			 % printHash16or32(actualHash));
+	    throw SubstError(format("hash mismatch for substituted item `%1%'") % storePath);
+	}
 
     } catch (SubstError & e) {
 
-- 
2.29.2





  parent reply	other threads:[~2020-12-06 22:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 10:13 [bug#45018] [PATCH 0/6] Process and connection reuse for substitutions Ludovic Courtès
2020-12-03 10:19 ` [bug#45018] [PATCH 1/6] daemon: 'Agent' constructor takes a list of environment variables Ludovic Courtès
2020-12-03 10:19   ` [bug#45018] [PATCH 2/6] daemon: Use 'Agent' to spawn 'guix substitute --query' Ludovic Courtès
2020-12-04  8:23     ` Mathieu Othacehe
2020-12-06 21:51       ` Ludovic Courtès
2020-12-03 10:19   ` [bug#45018] [PATCH 3/6] daemon: Factorize substituter agent spawning Ludovic Courtès
2020-12-04  8:19     ` Mathieu Othacehe
2020-12-03 10:19   ` [bug#45018] [PATCH 4/6] daemon: Run 'guix substitute --substitute' as an agent Ludovic Courtès
2020-12-04  8:27     ` Mathieu Othacehe
2020-12-06 21:53       ` Ludovic Courtès
2020-12-03 10:19   ` [bug#45018] [PATCH 5/6] substitute: Cache and reuse connections while substituting Ludovic Courtès
2020-12-03 10:19   ` [bug#45018] [PATCH 6/6] daemon: Raise an error if substituter doesn't send the expected hash Ludovic Courtès
2020-12-03 11:48 ` [bug#45018] [PATCH 0/6] Process and connection reuse for substitutions 宋文武
2020-12-03 20:52 ` Ludovic Courtès
2020-12-04  8:34   ` Mathieu Othacehe
2020-12-06 22:04     ` [bug#45018] [PATCH v2 " Ludovic Courtès
2020-12-06 22:04       ` [bug#45018] [PATCH v2 1/6] daemon: 'Agent' constructor takes a list of environment variables Ludovic Courtès
2020-12-06 22:04       ` [bug#45018] [PATCH v2 2/6] daemon: Use 'Agent' to spawn 'guix substitute --query' Ludovic Courtès
2020-12-06 22:04       ` [bug#45018] [PATCH v2 3/6] daemon: Factorize substituter agent spawning Ludovic Courtès
2020-12-06 22:04       ` [bug#45018] [PATCH v2 4/6] daemon: Run 'guix substitute --substitute' as an agent Ludovic Courtès
2020-12-06 22:04       ` [bug#45018] [PATCH v2 5/6] substitute: Cache and reuse connections while substituting Ludovic Courtès
2020-12-06 22:04       ` Ludovic Courtès [this message]
2020-12-08 22:39       ` bug#45018: [PATCH v2 0/6] Process and connection reuse for substitutions Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201206220415.23279-7-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=45018@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).