all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#54846] [PATCH] gnu: linux: Escape the values of string-type kconfig options
@ 2022-04-11  2:24 antlers
  2022-04-11  5:08 ` [bug#54713] " Elijah Harding
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: antlers @ 2022-04-11  2:24 UTC (permalink / raw)
  To: 54846; +Cc: antlers

 * 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(-)

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"))
 
-- 
2.34.0





^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-17 15:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-11  2:24 [bug#54846] [PATCH] gnu: linux: Escape the values of string-type kconfig options antlers
2022-04-11  5:08 ` [bug#54713] " Elijah Harding
2022-04-12 21:39 ` [bug#54846] " Ludovic Courtès
2022-04-28 12:16   ` Ludovic Courtès
2022-04-28 20:18 ` Antlers
2022-05-08  4:48   ` antlers
2022-05-17 15:54     ` bug#54846: " Antlers

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.