Skip to contentSkip to conversation

xen/cmdline: Fix parse_boolean() for unadorned values

PATCH In review Andrew Cooper 2 participants 2 messages Jan 31, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/cmdline: Fix parse_boolean() for unadorned values

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.

---
CC: Jan Beulich <[email protected]>

This wants backporting everywhere the spectre series has gone.

---
 xen/common/kernel.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
xen/common/kernel.c +10 -6
index 19f9bad..5766a0f 100644
@@ -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;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 31.01.18 at 11:36, <[email protected]> wrote:

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.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel