From db1775332c83a8d0943bea4b69c49ea5b47cc2a6 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 22 May 2023 11:34:32 +0100 Subject: Better handle invalid GET /nar/ requests --- nar-herder/server.scm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/nar-herder/server.scm b/nar-herder/server.scm index 07cb1c4..f07cb9d 100644 --- a/nar-herder/server.scm +++ b/nar-herder/server.scm @@ -283,20 +283,24 @@ (values (build-response #:code 404) "404")))) (('GET "nar" compression filename) - (let* ((hash (string-take filename 32)) + (let* ((hash (and (>= (string-length filename) 32) + (string-take filename 32))) (narinfo - (database-select-narinfo-by-hash - database - hash)) + (and hash + (database-select-narinfo-by-hash + database + hash))) (narinfo-files - (database-select-narinfo-files-by-narinfo-id - database - (assq-ref narinfo 'id))) + (and=> (assq-ref narinfo 'id) + (lambda (id) + (database-select-narinfo-files-by-narinfo-id + database + id)))) (narinfo-file-for-compression (find (lambda (file) (string=? (assq-ref file 'compression) compression)) - narinfo-files)) + (or narinfo-files '()))) (compression-symbol (if (member compression -- cgit v1.2.3