qapi: fix input visitor bugs
PATCH 1/1 qapi: fix input visitor bugs
Remove dead code. Reset errno to 0 before each strtoull call, as the man page requires.
--- qapi/string-input-visitor.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
qapi/string-input-visitor.c +4 -5
@@ -48,11 +48,10 @@ static void parse_str(StringInputVisitor *siv, Error **errp)return ; } - errno =0 ; do { + errno = 0; start = strtoll(str, &endptr, 0); - if (errno == 0 && endptr > str && INT64_MIN <= start && - start <= INT64_MAX) { + if (errno == 0 && endptr > str) { if (*endptr == '\0') { cur = g_malloc0(sizeof(*cur)); cur->begin = start;
@@ -63,9 +62,9 @@ static void parse_str(StringInputVisitor *siv, Error **errp) str =NULL ; }else if (*endptr =='-' ) { str = endptr +1 ; + errno =0 ; end =strtoll (str, &endptr,0 ); -if (errno ==0 && endptr > str && -INT64_MIN <= end && end <=INT64_MAX && start <= end && +if (errno ==0 && endptr > str && start <= end && (start >INT64_MAX -65536 || end < start +65536 )) {if (*endptr =='\0' ) {
Signature · 1 line
MST
Quoted 14 lines · Michael S. Tsirkin
Remove dead code. Reset errno to 0 before each strtoull call, as the man page requires.
Reported-by Eric Blake <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- qapi/string-input-visitor.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)qapi/string-input-visitor.c +0
-0
qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 54
Quoted 10 lines
qapi/string-input-visitor.c +2
-3@@ -48,11 +48,10 @@ static void parse_str(StringInputVisitor *siv, Error **errp)return ; } - errno =0 ; do { + errno = 0; start = strtoll(str, &endptr, 0); - if (errno == 0 && endptr > str && INT64_MIN <= start && - start <= INT64_MAX) { + if (errno == 0 && endptr > str) {
Based on this conditional...
qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 65
Quoted 8 lines
qapi/string-input-visitor.c +1
-0if (*endptr =='\0' ) { cur =g_malloc0 (sizeof (*cur)); cur->begin = start;@@ -63,9 +62,9 @@ static void parse_str(StringInputVisitor *siv, Error **errp) str =NULL ; }else if (*endptr =='-' ) { str = endptr +1 ; + errno =0 ;
...this assignment to errno is dead code (we already know it is 0). But I'd rather leave it in for robustness sake (any change to intermediate code may change the situation where we are no longer assured of the current value of errno at this point).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 28 lines · Eric Blake
Quoted 14 lines · Michael S. Tsirkin
Remove dead code. Reset errno to 0 before each strtoull call, as the man page requires.
Reported-by Eric Blake <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- qapi/string-input-visitor.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)qapi/string-input-visitor.c +0
-0qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 54
Quoted 10 lines
qapi/string-input-visitor.c +2
-3@@ -48,11 +48,10 @@ static void parse_str(StringInputVisitor *siv, Error **errp)return ; } - errno =0 ; do { + errno = 0; start = strtoll(str, &endptr, 0); - if (errno == 0 && endptr > str && INT64_MIN <= start && - start <= INT64_MAX) { + if (errno == 0 && endptr > str) {Based on this conditional...
Quoted 13 lines
qapi/string-input-visitor.c static void parse_str(StringInputVisitor *siv, Error **errp) · line 65
Quoted 8 lines
qapi/string-input-visitor.c +1
-0if (*endptr =='\0' ) { cur =g_malloc0 (sizeof (*cur)); cur->begin = start;@@ -63,9 +62,9 @@ static void parse_str(StringInputVisitor *siv, Error **errp) str =NULL ; }else if (*endptr =='-' ) { str = endptr +1 ; + errno =0 ;...this assignment to errno is dead code (we already know it is 0). But I'd rather leave it in for robustness sake (any change to intermediate code may change the situation where we are no longer assured of the current value of errno at this point).
Exactly, that's why I put it here.
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks!
Quoted 4 lines
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org