[libvirt] [PATCH 1/3] virsh: avoid strtol
Eric Blake
eblake at redhat.com
Thu Apr 19 17:52:55 UTC 2012
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 at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120419/af23accf/attachment-0001.sig>
More information about the libvir-list
mailing list