]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
xen/cmdline: Fix parse_boolean() for unadorned values
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 31 Jan 2018 10:35:52 +0000 (10:35 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 31 Jan 2018 10:47:12 +0000 (10:47 +0000)
A command line such as "cpuid=no-ibrsb,no-stibp" tickles a bug in
parse_boolean() because the separating comma fails the NUL case.

Instead, check for slen == nlen which accounts for the boundary (if any)
passed via the 'e' parameter.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/common/kernel.c

index 19f9bad48dfcac4a9c7865d6e594f67bb682b899..5766a0f784eb2525a6da10b7577aa7ab126a0369 100644 (file)
@@ -259,12 +259,16 @@ int parse_boolean(const char *name, const char *s, const char *e)
     if ( slen < nlen || strncmp(s, name, nlen) )
         return -1;
 
-    switch ( s[nlen] )
-    {
-    case '\0': return val;
-    case '=':  return parse_bool(&s[nlen + 1], e);
-    default:   return -1;
-    }
+    /* Exact, unadorned name?  Result depends on the 'no-' prefix. */
+    if ( slen == nlen )
+        return val;
+
+    /* =$SOMETHING?  Defer to the regular boolean parsing. */
+    if ( s[nlen] == '=' )
+        return parse_bool(&s[nlen + 1], e);
+
+    /* Unrecognised.  Give up. */
+    return -1;
 }
 
 unsigned int tainted;