qemu-io: Check for trailing chars

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>
This commit is contained in:
John Snow 2015-11-05 18:53:03 -05:00 committed by Kevin Wolf
parent 9b0beaf3de
commit ef5a788527
1 changed files with 8 additions and 1 deletions

View 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)