From df763d6a2d6fa9b3361ae3eac7924708169db908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 13 Jul 2025 12:43:13 +0200 Subject: [PATCH] git-authenticate: Print a clear error message for malformed keys. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes guix/guix#1141. * guix/git-authenticate.scm (load-keyring-from-blob): Change ‘oid’ to ‘entry’ and adjust accordingly. Raise a ‘&formatted-message’ error when ‘read-radix-64’ returns #f or EOF. (load-keyring-from-reference): Adjust accordingly. Change-Id: Ib88c94dac543caf6b1e0855242ba50063c944765 --- guix/git-authenticate.scm | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/guix/git-authenticate.scm b/guix/git-authenticate.scm index 3cd1175c326..ccd3e657405 100644 --- a/guix/git-authenticate.scm +++ b/guix/git-authenticate.scm @@ -246,13 +246,22 @@ key: ~a") signing-key) -(define (load-keyring-from-blob repository oid keyring) - "Augment KEYRING with the keyring available in the blob at OID, which may or -may not be ASCII-armored." - (let* ((blob (blob-lookup repository oid)) +(define (load-keyring-from-blob repository entry keyring) + "Augment KEYRING with the keyring available in ENTRY (a tree entry), which +may or may not be ASCII-armored." + (let* ((oid (tree-entry-id entry)) + (blob (blob-lookup repository oid)) (port (open-bytevector-input-port (blob-content blob)))) (get-openpgp-keyring (if (port-ascii-armored? port) - (open-bytevector-input-port (read-radix-64 port)) + (match (read-radix-64 port) + ((? bytevector? radix) + (open-bytevector-input-port radix)) + (_ + (raise + (formatted-message (G_ "malformed \ +ASCII-armored key in ~a (blob ~a)") + (tree-entry-name entry) + (oid->string oid))))) port) keyring))) @@ -266,9 +275,7 @@ an OpenPGP keyring." (fold (lambda (name keyring) (if (string-suffix? ".key" name) (let ((entry (tree-entry-bypath tree name))) - (load-keyring-from-blob repository - (tree-entry-id entry) - keyring)) + (load-keyring-from-blob repository entry keyring)) keyring)) %empty-keyring (tree-list tree))))