提交 e36b3695 编写于 作者: M Markus Armbruster 提交者: Anthony Liguori

qemu-img: Tighten parsing of size arguments

strtosz_suffix() fails unless the size is followed by 0, whitespace or
','.  Useless here, because we need to fail for any junk following the
size, even if it starts with whitespace or ','.  Check manually.
Things like "qemu-img create xxx 1024," and "qemu-img convert -S '1024
junk'" are now caught.
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 45009a30
...@@ -332,8 +332,9 @@ static int img_create(int argc, char **argv) ...@@ -332,8 +332,9 @@ static int img_create(int argc, char **argv)
/* Get image size, if specified */ /* Get image size, if specified */
if (optind < argc) { if (optind < argc) {
int64_t sval; int64_t sval;
sval = strtosz_suffix(argv[optind++], NULL, STRTOSZ_DEFSUFFIX_B); char *end;
if (sval < 0) { sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
if (sval < 0 || *end) {
error_report("Invalid image size specified! You may use k, M, G or " error_report("Invalid image size specified! You may use k, M, G or "
"T suffixes for "); "T suffixes for ");
error_report("kilobytes, megabytes, gigabytes and terabytes."); error_report("kilobytes, megabytes, gigabytes and terabytes.");
...@@ -710,8 +711,9 @@ static int img_convert(int argc, char **argv) ...@@ -710,8 +711,9 @@ static int img_convert(int argc, char **argv)
case 'S': case 'S':
{ {
int64_t sval; int64_t sval;
sval = strtosz_suffix(optarg, NULL, STRTOSZ_DEFSUFFIX_B); char *end;
if (sval < 0) { sval = strtosz_suffix(optarg, &end, STRTOSZ_DEFSUFFIX_B);
if (sval < 0 || *end) {
error_report("Invalid minimum zero buffer size for sparse output specified"); error_report("Invalid minimum zero buffer size for sparse output specified");
return 1; return 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册