Skip to content

Commit 4e264ff

Browse files
mhiramatrostedt
authored andcommitted
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: c1a3c36 ("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>
1 parent 6924372 commit 4e264ff

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎fs/proc/bootconfig.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ static int boot_config_proc_show(struct seq_file *m, void *v)
2626
static int __init copy_xbc_key_value_list(char *dst, size_t size)
2727
{
2828
struct xbc_node *leaf, *vnode;
29-
const char *val;
3029
char *key, *end = dst + size;
30+
const char *val;
31+
char q;
3132
int ret = 0;
3233

3334
key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL);
@@ -41,16 +42,20 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size)
4142
break;
4243
dst += ret;
4344
vnode = xbc_node_get_child(leaf);
44-
if (vnode && xbc_node_is_array(vnode)) {
45+
if (vnode) {
4546
xbc_array_for_each_value(vnode, val) {
46-
ret = snprintf(dst, rest(dst, end), "\"%s\"%s",
47-
val, vnode->next ? ", " : "\n");
47+
if (strchr(val, '"'))
48+
q = '\'';
49+
else
50+
q = '"';
51+
ret = snprintf(dst, rest(dst, end), "%c%s%c%s",
52+
q, val, q, vnode->next ? ", " : "\n");
4853
if (ret < 0)
4954
goto out;
5055
dst += ret;
5156
}
5257
} else {
53-
ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val);
58+
ret = snprintf(dst, rest(dst, end), "\"\"\n");
5459
if (ret < 0)
5560
break;
5661
dst += ret;

0 commit comments

Comments
 (0)