Skip to contentSkip to conversation

xen: fix parse_bool() with empty string

PATCH In review Juergen Gross 3 participants 3 messages Aug 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: fix parse_bool() with empty string

parse_bool() should return -1 in case it is called with an empty string. In order to allow boolean parameters in the cmdline without specifying a value this case must be handled in _cmdline_parse() by always passing a value string.

This fixes commit 532dec8e31174ed450adfd36a4b0b41dec27010d ("xen:
add an optional string end parameter to parse_bool()")

---
 xen/common/kernel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
xen/common/kernel.c +3 -1
index ec7714961a..71bc547d17 100644
@@ -114,7 +114,7 @@ static void __init _cmdline_parse(const char *cmdline)
                     simple_strtoll(optval, NULL, 0));
                 break;
             case OPT_BOOL:
-                if ( !parse_bool(optval, NULL) )
+                if ( !parse_bool(*optval ? optval : "yes", NULL) )
                     bool_assert = !bool_assert;
                 assign_integer_param(param, bool_assert);
                 break;
@@ -168,6 +168,8 @@ int __init parse_bool(const char *s, const char *e)
     unsigned int len;
 
     len = e ? ({ ASSERT(e >= s); e - s; }) : strlen(s);
+    if ( !len )
+        return -1;
 
     if ( !strncmp("no", s, len) ||
          !strncmp("off", s, len) ||
Signature · 7 lines
2.12.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Juergen Gross

parse_bool() should return -1 in case it is called with an empty string. In order to allow boolean parameters in the cmdline without specifying a value this case must be handled in _cmdline_parse() by always passing a value string.

This fixes commit 532dec8e31174ed450adfd36a4b0b41dec27010d ("xen:
add an optional string end parameter to parse_bool()")

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

#2 lore raw
Quoted 11 lines · Wei Liu
Quoted 9 lines · Juergen Gross

parse_bool() should return -1 in case it is called with an empty string. In order to allow boolean parameters in the cmdline without specifying a value this case must be handled in _cmdline_parse() by always passing a value string.

This fixes commit 532dec8e31174ed450adfd36a4b0b41dec27010d ("xen:
add an optional string end parameter to parse_bool()")

I've exercised this with some of the more weird callers of parse_bool(), and everything appears to be in order. Tested, Reviewed and committed, thanks.

~Andrew

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