Message ID | 20220411022410.5606-1-autumnalantlers@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org> X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B780127BBEA; Mon, 11 Apr 2022 03:25:40 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5585727BBE9 for <patchwork@mira.cbaines.net>; Mon, 11 Apr 2022 03:25:40 +0100 (BST) Received: from localhost ([::1]:54948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org>) id 1ndjkJ-0005p5-Bq for patchwork@mira.cbaines.net; Sun, 10 Apr 2022 22:25:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ndjk7-0005oO-Bg for guix-patches@gnu.org; Sun, 10 Apr 2022 22:25:27 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:48127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ndjjj-0000oe-0F for guix-patches@gnu.org; Sun, 10 Apr 2022 22:25:26 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ndjji-0005Tv-R1 for guix-patches@gnu.org; Sun, 10 Apr 2022 22:25:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54846] [PATCH] gnu: linux: Escape the values of string-type kconfig options Resent-From: antlers <autumnalantlers@gmail.com> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 11 Apr 2022 02:25:02 +0000 Resent-Message-ID: <handler.54846.B.164964389121049@debbugs.gnu.org> Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 54846 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54846@debbugs.gnu.org Cc: antlers <autumnalantlers@gmail.com> X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.164964389121049 (code B ref -1); Mon, 11 Apr 2022 02:25:02 +0000 Received: (at submit) by debbugs.gnu.org; 11 Apr 2022 02:24:51 +0000 Received: from localhost ([127.0.0.1]:42024 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1ndjjX-0005TR-HG for submit@debbugs.gnu.org; Sun, 10 Apr 2022 22:24:51 -0400 Received: from lists.gnu.org ([209.51.188.17]:42452) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <autumnalantlers@gmail.com>) id 1ndjjV-0005TJ-PG for submit@debbugs.gnu.org; Sun, 10 Apr 2022 22:24:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <autumnalantlers@gmail.com>) id 1ndjjV-0005iF-E5 for guix-patches@gnu.org; Sun, 10 Apr 2022 22:24:49 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:52151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <autumnalantlers@gmail.com>) id 1ndjjT-0000ji-Qd for guix-patches@gnu.org; Sun, 10 Apr 2022 22:24:49 -0400 Received: by mail-pj1-x1034.google.com with SMTP id bg24so1441717pjb.1 for <guix-patches@gnu.org>; Sun, 10 Apr 2022 19:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Oom+QP5LNVAGwFpKdZ0H6N8Ai8LljNt2dQbzziiAxwQ=; b=FbljAGSFV6xdroZB2Xoi5M+cq/k+JjGKNN0YO4gf1rMx1zydQWoptBlFZZu5XYjrwD s0ce71YBcv43FXHHRL6fsNLbNjm97dhfP8JqPUfvQJgf3fDxMpVSi4KsNXUNGCp+zhal uggxDMMjMQeM03iZyMRpAt47X3oiKCSQCO9rgsShdo9DU+gr9ph6rRRGXOn6ePK/3mQe Dfgd6ELJE7Z1lOT0FdyXg7kN7T7zUnAAVW1huUG94X2M+6C/5jyVXuzcUZuim6EAuBp6 fOVuYu72nP/t4Ssts3gfcBM/9ofQNuRF24R6k6IT+y0SSgEW1CfzIdl/38edx9PBpLd2 dF/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Oom+QP5LNVAGwFpKdZ0H6N8Ai8LljNt2dQbzziiAxwQ=; b=aC5xY006V/cRMtcNrX9BIyuRIq5DLTDbp6fvGpr6WRIeZUYGaiQ0kl/g1nZeWNrCW1 Skvl/xJ+udfJgsH4PvrhPJ3Jgh7nGQg0N9ahLClxsELmwxKZrTzy6+Cu7ZiqbXL6d9DC mamO2N/a5wQml0FfmjYPNnpKUQRFMN7dbiSkv1vGQ9Ql1/rBAODJfZR7lV9JxG9bsJCI MSMxRC0tlPSueQ7xXzNLxT4FqgZs2jRVOwiJC63NGlmB++dIOSRE0ueFriEUGyv/jOdR dppkMbDWPfwNeOUnFwTVv78QLzpoVPl+1AIvSbQCaLVAiB1nAyPPuzVhy/bWSYBrjyXq kucw== X-Gm-Message-State: AOAM532x1B1+IOspNt/gzVODZdVr4jXmodpflDqcpag3MyzU4xoHny98 PXRwyPHI90V7yw77Ab/nkmouPwVC73cN2A== X-Google-Smtp-Source: ABdhPJx+jzrG/4N1QYZIFS6GMQQEzLSnAr15DR+ytdgxeISZrkANuAVTHBkVCdBUjqUrk1EwhCSMzw== X-Received: by 2002:a17:90a:4403:b0:1ca:a4a3:6824 with SMTP id s3-20020a17090a440300b001caa4a36824mr33907973pjg.20.1649643866267; Sun, 10 Apr 2022 19:24:26 -0700 (PDT) Received: from tower.hitronhub.home (24-113-171-200.wavecable.com. [24.113.171.200]) by smtp.gmail.com with ESMTPSA id k62-20020a17090a4cc400b001c7ea7f487asm18774475pjh.39.2022.04.10.19.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 19:24:25 -0700 (PDT) From: antlers <autumnalantlers@gmail.com> Date: Sun, 10 Apr 2022 19:24:10 -0700 Message-Id: <20220411022410.5606-1-autumnalantlers@gmail.com> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=autumnalantlers@gmail.com; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: <guix-patches.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/guix-patches>, <mailto:guix-patches-request@gnu.org?subject=unsubscribe> List-Archive: <https://lists.gnu.org/archive/html/guix-patches> List-Post: <mailto:guix-patches@gnu.org> List-Help: <mailto:guix-patches-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/guix-patches>, <mailto:guix-patches-request@gnu.org?subject=subscribe> Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" <guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org> X-getmail-retrieved-from-mailbox: Patches |
Series |
[bug#54846] gnu: linux: Escape the values of string-type kconfig options
|
|
Commit Message
antlers
April 11, 2022, 2:24 a.m. UTC
* gnu/packages/linux.scm (config->string): add escape-string Handles characters within the set (char-set-intersection char-set:ascii char-set:printing), removing those which are known to be unsupported. --- gnu/packages/linux.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
Comments
Oh lord, hold off on this one: File paths in CONFIG_SYSTEM_*_KEYS options are parsed by Make before their file is opened, but CONFIG_LOCALVERSION strings aren't, nor are (I imagine?) CONFIG_INITRAMFS_SOURCE's despite also being file paths, so taking responsibility for escaping means handling several options individually :/
Hi, antlers <autumnalantlers@gmail.com> skribis: > * gnu/packages/linux.scm (config->string): add escape-string > > Handles characters within the set > (char-set-intersection char-set:ascii char-set:printing), removing > those which are known to be unsupported. [...] > (define (config->string options) > + (define (escape-string str) > + "Returns STR with the escapes necessary to be read as a string-type > + option's value. Handles characters within the set (char-set-intersection > + char-set:ascii char-set:printing), removing those which are known to be > + unsupported." Nitpick: You can turn the docstring into a comment since the docstring wouldn’t be accessible anyway. > + (fold (match-lambda* (((match? fmt) str) > + (transform-string str match? > + (cut format #f fmt <>)))) Please avoid tabs. ‘transform-string’ is from (texinfo string-utils), which is not imported here. IMO, we’d rather avoid depending on this module since it’s really designed for the Texinfo machinery. > + str > + `((#\# "") ; No known way to escape # characters. > + (#\$ "$~a") > + ("\"\\'`" "\\~a") > + (";:()#" "\\\\~a") > + ("|" "\\\\\\~a") > + ;; No support for tabs, newlines, etc. > + (,(char-set->string (ucs-range->char-set 9 14)) "")))) I wonder if this should be implemented in terms of ‘string-fold’ instead: (string-concatenate-reverse (string-fold (lambda (chr result) (match chr (#\# (cons "" result)) ;; … (_ (cons (string chr) result)))) '() str)) Thoughts? Thanks, Ludo’.
Hi antlers, Did you have a chance to look into it? TIA, Ludo’. Ludovic Courtès <ludo@gnu.org> skribis: > Hi, > > antlers <autumnalantlers@gmail.com> skribis: > >> * gnu/packages/linux.scm (config->string): add escape-string >> >> Handles characters within the set >> (char-set-intersection char-set:ascii char-set:printing), removing >> those which are known to be unsupported. > > [...] > >> (define (config->string options) >> + (define (escape-string str) >> + "Returns STR with the escapes necessary to be read as a string-type >> + option's value. Handles characters within the set (char-set-intersection >> + char-set:ascii char-set:printing), removing those which are known to be >> + unsupported." > > Nitpick: You can turn the docstring into a comment since the docstring > wouldn’t be accessible anyway. > >> + (fold (match-lambda* (((match? fmt) str) >> + (transform-string str match? >> + (cut format #f fmt <>)))) > > Please avoid tabs. > > ‘transform-string’ is from (texinfo string-utils), which is not imported > here. IMO, we’d rather avoid depending on this module since it’s really > designed for the Texinfo machinery. > >> + str >> + `((#\# "") ; No known way to escape # characters. >> + (#\$ "$~a") >> + ("\"\\'`" "\\~a") >> + (";:()#" "\\\\~a") >> + ("|" "\\\\\\~a") >> + ;; No support for tabs, newlines, etc. >> + (,(char-set->string (ucs-range->char-set 9 14)) "")))) > > I wonder if this should be implemented in terms of ‘string-fold’ > instead: > > (string-concatenate-reverse > (string-fold (lambda (chr result) > (match chr > (#\# (cons "" result)) > ;; … > (_ (cons (string chr) result)))) > '() > str)) > > Thoughts? > > Thanks, > Ludo’.
Yeah, sorry for the silence, there's been a lot going on and being able to use strings in the first place is a comportable baseline of functionality- I don't feel that one should implement implicit escaping of a field until confident that all the corner cases are handled, and think that there are some subtle warts left. Haven't had that time iron those out, but I'll be glad to polish the details and can follow up within about a week once I've addressed my remaining cornerns about correctness. Thanks for bearing with me I fumble my way through the conventions of the mailing list and formatting, nitpicks are what I'm here for c: I think transform-string is a gem for the task, the inputs are flexible and the author specifically cites better performance than string-fold in the (ice-9 texinfo) source, but I appreciate your point and can happily specialize it in-line. ---------------------------------------- Apr 28, 2022 5:16:46 AM Ludovic Courtès <ludo@gnu.org>: > Hi antlers, > > Did you have a chance to look into it? > > TIA, > Ludo’. > > Ludovic Courtès <ludo@gnu.org> skribis: > >> Hi, >> >> antlers <autumnalantlers@gmail.com> skribis: >> >>> * gnu/packages/linux.scm (config->string): add escape-string >>> >>> Handles characters within the set >>> (char-set-intersection char-set:ascii char-set:printing), removing >>> those which are known to be unsupported. >> >> [...] >> >>> (define (config->string options) >>> + (define (escape-string str) >>> + "Returns STR with the escapes necessary to be read as a string-type >>> + option's value. Handles characters within the set (char-set-intersection >>> + char-set:ascii char-set:printing), removing those which are known to be >>> + unsupported." >> >> Nitpick: You can turn the docstring into a comment since the docstring >> wouldn’t be accessible anyway. >> >>> + (fold (match-lambda* (((match? fmt) str) >>> + (transform-string str match? >>> + (cut format #f fmt <>)))) >> >> Please avoid tabs. >> >> ‘transform-string’ is from (texinfo string-utils), which is not imported >> here. IMO, we’d rather avoid depending on this module since it’s really >> designed for the Texinfo machinery. >> >>> + str >>> + `((#\# "") ; No known way to escape # characters. >>> + (#\$ "$~a") >>> + ("\"\\'`" "\\~a") >>> + (";:()#" "\\\\~a") >>> + ("|" "\\\\\\~a") >>> + ;; No support for tabs, newlines, etc. >>> + (,(char-set->string (ucs-range->char-set 9 14)) "")))) >> >> I wonder if this should be implemented in terms of ‘string-fold’ >> instead: >> >> (string-concatenate-reverse >> (string-fold (lambda (chr result) >> (match chr >> (#\# (cons "" result)) >> ;; … >> (_ (cons (string chr) result)))) >> '() >> str)) >> >> Thoughts? >> >> Thanks, >> Ludo’.
Hi! Still a busy week, working retail will do that, but this investigation has been on the back burner long enough that it's become clear; the kernel provides no reliable heuristic for determining the appropriate escapes for a given option (least of all for out-of-tree modules). Some options are explicitly expanded in Makefiles, others aren't but become parts of filenames which are, and every special character seems to create a syntax error on a whole new layer :c I'm short on time to write anything up tonight, but have explored the 'behavior of', 'supported escapes within', and 'unsupported characters of' CONFIG_SYSTEM_*_KEYS, CONFIG_CMDLINE, CONFIG_LOCALVERSION, and CONFIG_DEFAULT_HOSTNAME (complete with associated errors for unsupported chars within the set I initially referenced), and would be glad to follow up with a brief summary purely for posterity; but there's simply no elegant or complete approach unless this were to be addressed by upstream(s). It's clearly peeved of me, and I'd take it to those Makefiles, but for similar issues in out-of-tree modules that I don't think I could address. It's been a lot of fun though. I suppose we could factor out the escapes which are common to all fields (which could be seen as eliminating /a/ layer, that of Kconfig/conf.c itself), or address only specific common options (not a serious suggestion!), but these each feel like inelegant solutions which are more likely to introduce additional confusion when an option doesn't behave correctly as transcribed out of a .config file, hence my all-or-nothing mindset. While I'm here, I once wrote a bash script which would set options via the kernel's 'config' utility (not worth using over the existing method of appending to .config, doesn't do any validation), and was having issues with some configurations because not every option I tried to set had it's dependency clauses satisfied. This isn't an issue when using menuconfig because options don't even appear until their dependencies are satisfied, but scripts can't tell whether the options they're setting are visible. At the time I just had it double-check after a run of `make oldconfig` (when validation is actually done) and emit warnings. I'm not confident that it caught every issue by just using the 'config' utility or grepping .config, but it was good enough. Now, I've got this crazy idea to compile conf.c as a shared library and link against it at runtime via Guile's FFI, in order to a) learn how that works(!), and b) use the kernels own utilities to reconstruct the options-graph (a 'menu' object) and emit correct warnings when setting options that aren't visible, or even actively ensure dependencies are satisfied. In brief, would this be Guix-y?
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index b31fe0a580..60ae668fd9 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -761,6 +761,22 @@ (define %bpf-extra-linux-options ("CONFIG_IKHEADERS" . #t))) (define (config->string options) + (define (escape-string str) + "Returns STR with the escapes necessary to be read as a string-type + option's value. Handles characters within the set (char-set-intersection + char-set:ascii char-set:printing), removing those which are known to be + unsupported." + (fold (match-lambda* (((match? fmt) str) + (transform-string str match? + (cut format #f fmt <>)))) + str + `((#\# "") ; No known way to escape # characters. + (#\$ "$~a") + ("\"\\'`" "\\~a") + (";:()#" "\\\\~a") + ("|" "\\\\\\~a") + ;; No support for tabs, newlines, etc. + (,(char-set->string (ucs-range->char-set 9 14)) "")))) (string-join (map (match-lambda ((option . 'm) (string-append option "=m")) @@ -769,7 +785,9 @@ (define (config->string options) ((option . #f) (string-append option "=n")) ((option . string) - (string-append option "=\"" string "\""))) + (string-append option "=\"" + (escape-string string) + "\""))) options) "\n"))