From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:39489) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5BYG-0004eR-Dp for guix-patches@gnu.org; Tue, 03 Sep 2019 12:21:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i5BYE-0002Dg-RA for guix-patches@gnu.org; Tue, 03 Sep 2019 12:21:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51682) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i5BYE-0002D2-Nt for guix-patches@gnu.org; Tue, 03 Sep 2019 12:21:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i5BYE-0000gO-Hz for guix-patches@gnu.org; Tue, 03 Sep 2019 12:21:02 -0400 Subject: [bug#36976] [Patch v2] guix download: Ensure destination file-name is valid in the store. References: <20190808144448.25147-1-h.goebel@crazy-compilers.com> In-Reply-To: <20190808144448.25147-1-h.goebel@crazy-compilers.com> Resent-Message-ID: From: Hartmut Goebel Date: Tue, 3 Sep 2019 18:20:28 +0200 Message-Id: <20190903162028.5373-1-h.goebel@crazy-compilers.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 36976@debbugs.gnu.org Avoid invalid store-file-name by explicitly passing the destination name, replacing any character not allowed in the store-file-name by an underscore. Fixes * guix/scripts/download.scm (safe-naensure-valid-store-file-nameme): New function. (download-to-store*): Use it to generate a "safe" basename of URL. --- guix/scripts/download.scm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guix/scripts/download.scm b/guix/scripts/download.scm index d8fe71ce12..22cd75ea0b 100644 --- a/guix/scripts/download.scm +++ b/guix/scripts/download.scm @@ -33,6 +33,7 @@ #:use-module (web uri) #:use-module (ice-9 match) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-14) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) #:use-module (rnrs bytevectors) @@ -54,9 +55,23 @@ (url-fetch url file #:mirrors %mirrors))) file)) +(define (ensure-valid-store-file-name name) + "Replace any character not allowed in a stror name by an underscore." + + (define valid + ;; according to nix/libstore/store-api.cc + (string->char-set (string-append "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789" "+-._?="))) + (string-map (lambda (c) + (if (char-set-contains? valid c) c #\_)) + name)) + + (define* (download-to-store* url #:key (verify-certificate? #t)) (with-store store (download-to-store store url + (ensure-valid-store-file-name (basename url)) #:verify-certificate? verify-certificate?))) (define %default-options -- 2.21.0