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

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



On 04/18/2012 06:59 PM, Stefan Berger wrote:
> 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)

The old code rejected 0,

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

but the new code allows it.  v2 coming up.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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