lkml.org 
[lkml]   [2020]   [Jun]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.7 464/477] proc/bootconfig: Fix to use correct quotes for value
    Date
    From: Masami Hiramatsu <mhiramat@kernel.org>

    commit 4e264ffd953463cd14c0720eaa9315ac052f5973 upstream.

    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>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    fs/proc/bootconfig.c | 15 ++++++++++-----
    1 file changed, 10 insertions(+), 5 deletions(-)

    --- a/fs/proc/bootconfig.c
    +++ b/fs/proc/bootconfig.c
    @@ -26,8 +26,9 @@ static int boot_config_proc_show(struct
    static int __init copy_xbc_key_value_list(char *dst, size_t size)
    {
    struct xbc_node *leaf, *vnode;
    - const char *val;
    char *key, *end = dst + size;
    + const char *val;
    + char q;
    int ret = 0;

    key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL);
    @@ -41,16 +42,20 @@ static int __init copy_xbc_key_value_lis
    break;
    dst += ret;
    vnode = xbc_node_get_child(leaf);
    - if (vnode && xbc_node_is_array(vnode)) {
    + if (vnode) {
    xbc_array_for_each_value(vnode, val) {
    - ret = snprintf(dst, rest(dst, end), "\"%s\"%s",
    - val, vnode->next ? ", " : "\n");
    + if (strchr(val, '"'))
    + q = '\'';
    + else
    + q = '"';
    + ret = snprintf(dst, rest(dst, end), "%c%s%c%s",
    + q, val, q, vnode->next ? ", " : "\n");
    if (ret < 0)
    goto out;
    dst += ret;
    }
    } else {
    - ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val);
    + ret = snprintf(dst, rest(dst, end), "\"\"\n");
    if (ret < 0)
    break;
    dst += ret;

    \
     
     \ /
      Last update: 2020-06-23 23:24    [W:2.772 / U:0.160 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site