mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00
option: Fix checking of sizes for overflow and trailing crap
parse_option_size()'s checking for overflow and trailing crap is wrong. Has always been that way. qemu_strtosz() gets it right, so use that. This adds support for size suffixes 'P', 'E', and ignores case for all suffixes, not just 'k'. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1487708048-2131-25-git-send-email-armbru@redhat.com>
This commit is contained in:
parent
f46bfdbfc8
commit
75cdcd1553
2 changed files with 22 additions and 40 deletions
|
@ -174,39 +174,24 @@ static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
|
|||
void parse_option_size(const char *name, const char *value,
|
||||
uint64_t *ret, Error **errp)
|
||||
{
|
||||
char *postfix;
|
||||
double sizef;
|
||||
uint64_t size;
|
||||
int err;
|
||||
|
||||
sizef = strtod(value, &postfix);
|
||||
if (sizef < 0 || sizef > UINT64_MAX) {
|
||||
err = qemu_strtosz(value, NULL, &size);
|
||||
if (err == -ERANGE) {
|
||||
error_setg(errp, "Value '%s' is too large for parameter '%s'",
|
||||
value, name);
|
||||
return;
|
||||
}
|
||||
if (err) {
|
||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name,
|
||||
"a non-negative number below 2^64");
|
||||
error_append_hint(errp, "Optional suffix k, M, G, T, P or E means"
|
||||
" kilo-, mega-, giga-, tera-, peta-\n"
|
||||
"and exabytes, respectively.\n");
|
||||
return;
|
||||
}
|
||||
switch (*postfix) {
|
||||
case 'T':
|
||||
sizef *= 1024;
|
||||
/* fall through */
|
||||
case 'G':
|
||||
sizef *= 1024;
|
||||
/* fall through */
|
||||
case 'M':
|
||||
sizef *= 1024;
|
||||
/* fall through */
|
||||
case 'K':
|
||||
case 'k':
|
||||
sizef *= 1024;
|
||||
/* fall through */
|
||||
case 'b':
|
||||
case '\0':
|
||||
*ret = (uint64_t) sizef;
|
||||
break;
|
||||
default:
|
||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
|
||||
error_append_hint(errp, "You may use k, M, G or T suffixes for "
|
||||
"kilobytes, megabytes, gigabytes and terabytes.\n");
|
||||
return;
|
||||
}
|
||||
*ret = size;
|
||||
}
|
||||
|
||||
bool has_help_option(const char *param)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue