[libvirt] [PATCH] Allow relative path for qemu backing file

Eric Blake eblake at redhat.com
Tue Apr 5 17:00:21 UTC 2011


On 04/05/2011 10:55 AM, Jesse J Cook wrote:
>>> +        if ('/' != *(vol->backingStore.path)) {
>>> +            virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
>>> +                        vol->backingStore.path);
>>> +
>>> +        } else {
>>> +            virAsprintf(&absolutePath, "%s", vol->backingStore.path);
>>
>> strdup is more efficient here, and avoiding malloc in the first place
>> even more so.
>>
>>> +        }
>>> +        accessRetCode = access(absolutePath, R_OK);
>>
>> This could segfault on OOM.
>>
>>> +        VIR_FREE(absolutePath);
> 
> I believe there needs to be a NULL check here or absolute paths and
> virAsprintf errors will segfault. I can patch if you don't beat me to
> it.

How so?  absolutePath was initialized as NULL; is only ever set to
non-null by a successful virAsprintf, and VIR_FREE works correctly
(no-op) on a NULL argument.  Put another way, are you missing that
VIR_FREE already has an embedded NULL check?

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110405/b6641c67/attachment-0001.sig>


More information about the libvir-list mailing list