|
|
7711c0 |
From 0a0c3e3e1453856848ff9ee25ecc98045f89e194 Mon Sep 17 00:00:00 2001
|
|
|
7711c0 |
From: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Date: Wed, 27 Mar 2019 17:22:41 +0100
|
|
|
7711c0 |
Subject: [PATCH 103/163] qemu-nbd: Avoid strtol open-coding
|
|
|
7711c0 |
|
|
|
7711c0 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Message-id: <20190327172308.31077-29-jsnow@redhat.com>
|
|
|
7711c0 |
Patchwork-id: 85191
|
|
|
7711c0 |
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 28/55] qemu-nbd: Avoid strtol open-coding
|
|
|
7711c0 |
Bugzilla: 1691009
|
|
|
7711c0 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
7711c0 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
From: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
|
|
|
7711c0 |
Our copy-and-pasted open-coding of strtol handling forgot to
|
|
|
7711c0 |
handle overflow conditions. Use qemu_strto*() instead.
|
|
|
7711c0 |
|
|
|
7711c0 |
In the case of --partition, since we insist on a user-supplied
|
|
|
7711c0 |
partition to be non-zero, we can use 0 rather than -1 for our
|
|
|
7711c0 |
initial value to distinguish when a partition is not being
|
|
|
7711c0 |
served, for slightly more optimal code.
|
|
|
7711c0 |
|
|
|
7711c0 |
The error messages for out-of-bounds values are less specific,
|
|
|
7711c0 |
but should not be a terrible loss in quality.
|
|
|
7711c0 |
|
|
|
7711c0 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
7711c0 |
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
7711c0 |
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
|
|
|
7711c0 |
Message-Id: <20190117193658.16413-8-eblake@redhat.com>
|
|
|
7711c0 |
(cherry picked from commit 43b510113bb2c6393c98a31dae9b57022a9c5636)
|
|
|
7711c0 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
7711c0 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
7711c0 |
---
|
|
|
7711c0 |
qemu-nbd.c | 28 +++++++++-------------------
|
|
|
7711c0 |
1 file changed, 9 insertions(+), 19 deletions(-)
|
|
|
7711c0 |
|
|
|
7711c0 |
diff --git a/qemu-nbd.c b/qemu-nbd.c
|
|
|
7711c0 |
index 598caa6..efca0e4 100644
|
|
|
7711c0 |
--- a/qemu-nbd.c
|
|
|
7711c0 |
+++ b/qemu-nbd.c
|
|
|
7711c0 |
@@ -546,9 +546,8 @@ int main(int argc, char **argv)
|
|
|
7711c0 |
};
|
|
|
7711c0 |
int ch;
|
|
|
7711c0 |
int opt_ind = 0;
|
|
|
7711c0 |
- char *end;
|
|
|
7711c0 |
int flags = BDRV_O_RDWR;
|
|
|
7711c0 |
- int partition = -1;
|
|
|
7711c0 |
+ int partition = 0;
|
|
|
7711c0 |
int ret = 0;
|
|
|
7711c0 |
bool seen_cache = false;
|
|
|
7711c0 |
bool seen_discard = false;
|
|
|
7711c0 |
@@ -660,9 +659,8 @@ int main(int argc, char **argv)
|
|
|
7711c0 |
port = optarg;
|
|
|
7711c0 |
break;
|
|
|
7711c0 |
case 'o':
|
|
|
7711c0 |
- dev_offset = strtoll (optarg, &end, 0);
|
|
|
7711c0 |
- if (*end) {
|
|
|
7711c0 |
- error_report("Invalid offset `%s'", optarg);
|
|
|
7711c0 |
+ if (qemu_strtou64(optarg, NULL, 0, &dev_offset) < 0) {
|
|
|
7711c0 |
+ error_report("Invalid offset '%s'", optarg);
|
|
|
7711c0 |
exit(EXIT_FAILURE);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
break;
|
|
|
7711c0 |
@@ -684,13 +682,9 @@ int main(int argc, char **argv)
|
|
|
7711c0 |
flags &= ~BDRV_O_RDWR;
|
|
|
7711c0 |
break;
|
|
|
7711c0 |
case 'P':
|
|
|
7711c0 |
- partition = strtol(optarg, &end, 0);
|
|
|
7711c0 |
- if (*end) {
|
|
|
7711c0 |
- error_report("Invalid partition `%s'", optarg);
|
|
|
7711c0 |
- exit(EXIT_FAILURE);
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
- if (partition < 1 || partition > 8) {
|
|
|
7711c0 |
- error_report("Invalid partition %d", partition);
|
|
|
7711c0 |
+ if (qemu_strtoi(optarg, NULL, 0, &partition) < 0 ||
|
|
|
7711c0 |
+ partition < 1 || partition > 8) {
|
|
|
7711c0 |
+ error_report("Invalid partition '%s'", optarg);
|
|
|
7711c0 |
exit(EXIT_FAILURE);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
break;
|
|
|
7711c0 |
@@ -711,15 +705,11 @@ int main(int argc, char **argv)
|
|
|
7711c0 |
device = optarg;
|
|
|
7711c0 |
break;
|
|
|
7711c0 |
case 'e':
|
|
|
7711c0 |
- shared = strtol(optarg, &end, 0);
|
|
|
7711c0 |
- if (*end) {
|
|
|
7711c0 |
+ if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 ||
|
|
|
7711c0 |
+ shared < 1) {
|
|
|
7711c0 |
error_report("Invalid shared device number '%s'", optarg);
|
|
|
7711c0 |
exit(EXIT_FAILURE);
|
|
|
7711c0 |
}
|
|
|
7711c0 |
- if (shared < 1) {
|
|
|
7711c0 |
- error_report("Shared device number must be greater than 0");
|
|
|
7711c0 |
- exit(EXIT_FAILURE);
|
|
|
7711c0 |
- }
|
|
|
7711c0 |
break;
|
|
|
7711c0 |
case 'f':
|
|
|
7711c0 |
fmt = optarg;
|
|
|
7711c0 |
@@ -1007,7 +997,7 @@ int main(int argc, char **argv)
|
|
|
7711c0 |
}
|
|
|
7711c0 |
fd_size -= dev_offset;
|
|
|
7711c0 |
|
|
|
7711c0 |
- if (partition != -1) {
|
|
|
7711c0 |
+ if (partition) {
|
|
|
7711c0 |
uint64_t limit;
|
|
|
7711c0 |
|
|
|
7711c0 |
if (dev_offset) {
|
|
|
7711c0 |
--
|
|
|
7711c0 |
1.8.3.1
|
|
|
7711c0 |
|