On 11/30/18 4:03 PM, Eric Blake wrote:
Our open-coding of strtol handling forgot to handle overflow
conditions. What's more, since we insiste on a user-supplied
partition to be non-zero, we can use 0 rather than -1 for our
initial value to distinguish when a partition is not being
served, for slightly more optimal code.

Signed-off-by: Eric Blake <ebl...@redhat.com>
---
  qemu-nbd.c | 14 +++++---------
  1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index 55e29bd9a7e..866e64779f1 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -546,7 +546,7 @@ int main(int argc, char **argv)
      int opt_ind = 0;
      char *end;
      int flags = BDRV_O_RDWR;
-    int partition = -1;
+    int partition = 0;
      int ret = 0;
      bool seen_cache = false;
      bool seen_discard = false;
@@ -685,13 +685,9 @@ int main(int argc, char **argv)
              flags &= ~BDRV_O_RDWR;
              break;
          case 'P':
-            partition = strtol(optarg, &end, 0);
-            if (*end) {
-                error_report("Invalid partition `%s'", optarg);
-                exit(EXIT_FAILURE);
-            }
-            if (partition < 1 || partition > 8) {
-                error_report("Invalid partition %d", partition);
+            if (qemu_strtoi(optarg, NULL, 0, &partition) < 0 ||

Hmm - the fact that 'char *end' is not a dead variable means there are more uses of strtoll() that need fixing. I'll get those in v2.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Reply via email to