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.