From: John Snow Date: Thu, 5 Nov 2015 23:53:03 +0000 (-0500) Subject: qemu-io: Check for trailing chars X-Git-Tag: v2.5.0-rc0~14^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef5a788527b2038d742b057a415ab4d0e735e98f;p=thirdparty%2Fqemu.git qemu-io: Check for trailing chars Make sure there's not trailing garbage, e.g. "64k-whatever-i-want-here" Reported-by: Max Reitz Signed-off-by: John Snow Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 1e97f69f565..7ebe89a1d8c 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -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)