Re: [PATCH 1/3] virsh: avoid strtol

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04/18/2012 08:14 PM, Eric Blake wrote:
We were forgetting to check errno for overflow.

* tools/virsh.c (get_integer_keycode, vshCommandOptInt)
(vshCommandOptUInt, vshCommandOptUL, vshCommandOptLongLong)
(vshCommandOptULongLong): Rewrite to be safer.
---
  tools/virsh.c |   66 ++++++++++++++++----------------------------------------
  1 files changed, 19 insertions(+), 47 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 95ed7bc..3ec853b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -5758,14 +5758,11 @@ static const vshCmdOptDef opts_send_key[] = {

  static int get_integer_keycode(const char *key_name)
  {
-    long val;
-    char *endptr;
-
-    val = strtol(key_name,&endptr, 0);
-    if (*endptr != '\0' || val>  0xffff || val<= 0)
-         return -1;
+    int ret;

-    return val;
+    if (virStrToLong_i(key_name, NULL, 0,&ret)<  0 || ret>  0xffff)
+        return -1;
+    return ret;
  }

  static bool

Looks like a replacement pattern repeated a couple of times.

  ACK.

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]