From patchwork Thu Dec 3 10:19:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 25551 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id F05AE27BBFC; Thu, 3 Dec 2020 10:20:55 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6853227BBFB for ; Thu, 3 Dec 2020 10:20:55 +0000 (GMT) Received: from localhost ([::1]:53798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkljK-00056M-J9 for patchwork@mira.cbaines.net; Thu, 03 Dec 2020 05:20:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkliW-0004Rw-J1 for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:55174) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kkliW-0006RY-Ai for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kkliW-0000G7-6F for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45018] [PATCH 6/6] daemon: Raise an error if substituter doesn't send the expected hash. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 03 Dec 2020 10:20:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45018 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45018@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 45018-submit@debbugs.gnu.org id=B45018.1606990800939 (code B ref 45018); Thu, 03 Dec 2020 10:20:04 +0000 Received: (at 45018) by debbugs.gnu.org; 3 Dec 2020 10:20:00 +0000 Received: from localhost ([127.0.0.1]:38481 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkliS-0000F1-Eg for submit@debbugs.gnu.org; Thu, 03 Dec 2020 05:20:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47676) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkliQ-0000EB-Pd for 45018@debbugs.gnu.org; Thu, 03 Dec 2020 05:19:59 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:40711) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkliL-0006LM-Kk; Thu, 03 Dec 2020 05:19:53 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=49238 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kkliK-0007oh-PH; Thu, 03 Dec 2020 05:19:53 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 3 Dec 2020 11:19:30 +0100 Message-Id: <20201203101930.11210-6-ludo@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201203101930.11210-1-ludo@gnu.org> References: <20201203101930.11210-1-ludo@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 50d300253d..b19181d51f 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) {