qemu-io: Check for trailing chars
authorJohn Snow <jsnow@redhat.com>
Thu, 5 Nov 2015 23:53:03 +0000 (18:53 -0500)
committerKevin Wolf <kwolf@redhat.com>
Wed, 11 Nov 2015 15:40:10 +0000 (16:40 +0100)
Make sure there's not trailing garbage, e.g.
"64k-whatever-i-want-here"

Reported-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
qemu-io-cmds.c

index 1e97f69f56576d44bc061a9490f73799ce2665f7..7ebe89a1d8cc506e09d2656a7f1dd0e79c5d5d2a 100644 (file)
@@ -136,7 +136,14 @@ static char **breakline(char *input, int *count)
 static int64_t cvtnum(const char *s)
 {
     char *end;
-    return qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
+    int64_t ret;
+
+    ret = qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
+    if (*end != '\0') {
+        /* Detritus at the end of the string */
+        return -EINVAL;
+    }
+    return ret;
 }
 
 #define EXABYTES(x)     ((long long)(x) << 60)