[libvirt] [PATCHv2 2/3] conf: tighten up XML integer parsing

Eric Blake eblake at redhat.com
Fri Apr 20 00:52:28 UTC 2012


On 04/19/2012 06:33 PM, Laine Stump wrote:
> On 04/19/2012 02:24 PM, Eric Blake wrote:
>> https://bugzilla.redhat.com/show_bug.cgi?id=617711 reported that
>> even with my recent patched to allow <memory unit='G'>1</memory>,
>> people can still get away with trying <memory>1G</memory> and
>> silently get <memory unit='KiB'>1</memory> instead.  While
>> virt-xml-validate catches the error, our C parser did not.
>>
>> Not to mention that it's always fun to fix bugs while reducing
>> lines of code.  :)
>>

>> -        char *end = NULL;
>> -        perms->mode = strtol(mode, &end, 8);
>> -        if (*end || (perms->mode & ~0777)) {
>> +        int tmp;
>> +
>> +        if (virStrToLong_i(mode, NULL, 8, &tmp) < 0 || (tmp & ~0777)) {
>>              VIR_FREE(mode);
>>              virStorageReportError(VIR_ERR_XML_ERROR,
>>                                    "%s", _("malformed octal mode"));
>>              goto error;
>>          }
>> +        perms->mode = tmp;
> 
> 
> I'm curious why in the case of clock.data.variable.adjustment, you
> switched it to do the conversion directly into the object attribute,
> while in this case you switched it in the opposite direction.

virStrToLong_i() requires an int, but we are not guaranteed that mode_t
is an int, so I had to go through a temporary here.

> ACK, in any case.

Thanks for the reviews.  I've pushed the series.

-- 
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/af6e9b3e/attachment-0001.sig>


More information about the libvir-list mailing list