[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
25/87: daemon: Improve error message for wrong hash sizes.
From: |
guix-commits |
Subject: |
25/87: daemon: Improve error message for wrong hash sizes. |
Date: |
Mon, 9 Jan 2023 18:27:30 -0500 (EST) |
mbakke pushed a commit to branch staging
in repository guix.
commit 407175a1d0e29f45639e7f28a531b3981cd20085
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Jan 9 16:48:01 2023 +0100
daemon: Improve error message for wrong hash sizes.
* nix/libutil/hash.cc (parseHash): Show the hash algorithm name and
expected size in the error message.
* tests/derivations.scm ("fixed-output derivation, invalid hash size"):
New test.
---
nix/libutil/hash.cc | 7 +++++--
tests/derivations.scm | 12 ++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc
index 9ba604eb85..9b83ffcdd9 100644
--- a/nix/libutil/hash.cc
+++ b/nix/libutil/hash.cc
@@ -76,8 +76,11 @@ string printHash(const Hash & hash)
Hash parseHash(HashType ht, const string & s)
{
Hash hash(ht);
- if (s.length() != hash.hashSize * 2)
- throw Error(format("invalid hash `%1%'") % s);
+ if (s.length() != hash.hashSize * 2) {
+ string algo = gcry_md_algo_name(ht);
+ throw Error(format("invalid %1% hash '%2%' (%3% bytes but expected
%4%)")
+ % algo % s % (s.length() / 2) % hash.hashSize);
+ }
for (unsigned int i = 0; i < hash.hashSize; i++) {
string s2(s, i * 2, 2);
if (!isxdigit(s2[0]) || !isxdigit(s2[1]))
diff --git a/tests/derivations.scm b/tests/derivations.scm
index 3d25365b14..66c777cfe7 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -396,6 +396,18 @@
(call-with-input-file p get-bytevector-all))
(bytevector? (query-path-hash %store p)))))))
+(test-assert "fixed-output derivation, invalid hash size"
+ (guard (c ((store-protocol-error? c)
+ (string-contains-ci (store-protocol-error-message c)
+ "invalid SHA512 hash")))
+ (derivation %store "download-with-invalid-hash"
+ "builtin:download" '()
+ #:env-vars `(("url"
+ . ,(object->string "http://example.org")))
+ #:hash-algo 'sha512
+ #:hash #vu8(1 2 3))
+ #f))
+
(test-assert "derivation with a fixed-output input"
;; A derivation D using a fixed-output derivation F doesn't has the same
;; output path when passed F or F', as long as F and F' have the same output
- 04/87: gnu: java-jgit-4.2: Remove trailing #T from build phase., (continued)
- 04/87: gnu: java-jgit-4.2: Remove trailing #T from build phase., guix-commits, 2023/01/09
- 05/87: gnu: java-cisd-args4j: Remove trailing #T from build phase., guix-commits, 2023/01/09
- 08/87: gnu: Remove java-ecj-3.5., guix-commits, 2023/01/09
- 10/87: gnu: java-cisd-jhdf5: Remove trailing #T., guix-commits, 2023/01/09
- 11/87: gnu: java-cisd-jhdf5: Do not override default JDK., guix-commits, 2023/01/09
- 14/87: gnu: Remove java-ecj-3., guix-commits, 2023/01/09
- 15/87: gnu: python-afdko: Fix failing tests., guix-commits, 2023/01/09
- 21/87: services: base: Add environment support to guix-configuration., guix-commits, 2023/01/09
- 23/87: substitute: Parse '_NIX_OPTIONS' once., guix-commits, 2023/01/09
- 24/87: derivations: 'read-derivation' correctly handles case with empty hash., guix-commits, 2023/01/09
- 25/87: daemon: Improve error message for wrong hash sizes.,
guix-commits <=
- 26/87: read-print: Do not use extended notation when printing '1+', '1-', etc., guix-commits, 2023/01/09
- 28/87: gnu: Add minetest-mobs-monster., guix-commits, 2023/01/09
- 34/87: gnu: r-rstpm2: Update to 1.5.9., guix-commits, 2023/01/09
- 36/87: gnu: r-timedate: Update to 4022.108., guix-commits, 2023/01/09
- 37/87: gnu: r-mitml: Update to 0.4-4., guix-commits, 2023/01/09
- 31/87: gnu: Add r-httr2., guix-commits, 2023/01/09
- 47/87: gnu: r-precrec: Update to 0.14.1., guix-commits, 2023/01/09
- 22/87: doc: cookbook: Add "Installing Guix on a Cluster" chapter., guix-commits, 2023/01/09
- 30/87: news: Add 'de' translation., guix-commits, 2023/01/09
- 32/87: gnu: r-collections: Update to 0.3.7., guix-commits, 2023/01/09