Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

proc/bootconfig: Fix to use correct quotes for value

Fix /proc/bootconfig to select double or single quotes
corrctly according to the value.

If a bootconfig value includes a double quote character,
we must use single-quotes to quote that value.

This modifies if() condition and blocks for avoiding
double-quote in value check in 2 places. Anyway, since
xbc_array_for_each_value() can handle the array which
has a single node correctly.
Thus,

if (vnode && xbc_node_is_array(vnode)) {
xbc_array_for_each_value(vnode) /* vnode->next != NULL */
...
} else {
snprintf(val); /* val is an empty string if !vnode */
}

is equivalent to

if (vnode) {
xbc_array_for_each_value(vnode) /* vnode->next can be NULL */
...
} else {
snprintf(""); /* value is always empty */
}

Link: http://lkml.kernel.org/r/159230244786.65555.3763894451251622488.stgit@devnote2

Cc: stable@vger.kernel.org
Fixes: c1a3c36017d4 ("proc: bootconfig: Add /proc/bootconfig to show boot config list")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
4e264ffd 69243720

+10 -5
+10 -5
fs/proc/bootconfig.c
··· 26 26 static int __init copy_xbc_key_value_list(char *dst, size_t size) 27 27 { 28 28 struct xbc_node *leaf, *vnode; 29 - const char *val; 30 29 char *key, *end = dst + size; 30 + const char *val; 31 + char q; 31 32 int ret = 0; 32 33 33 34 key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL); ··· 42 41 break; 43 42 dst += ret; 44 43 vnode = xbc_node_get_child(leaf); 45 - if (vnode && xbc_node_is_array(vnode)) { 44 + if (vnode) { 46 45 xbc_array_for_each_value(vnode, val) { 47 - ret = snprintf(dst, rest(dst, end), "\"%s\"%s", 48 - val, vnode->next ? ", " : "\n"); 46 + if (strchr(val, '"')) 47 + q = '\''; 48 + else 49 + q = '"'; 50 + ret = snprintf(dst, rest(dst, end), "%c%s%c%s", 51 + q, val, q, vnode->next ? ", " : "\n"); 49 52 if (ret < 0) 50 53 goto out; 51 54 dst += ret; 52 55 } 53 56 } else { 54 - ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val); 57 + ret = snprintf(dst, rest(dst, end), "\"\"\n"); 55 58 if (ret < 0) 56 59 break; 57 60 dst += ret;