[libvirt] [PATCH] build: avoid unsafe functions in libgen.h
Eric Blake
eblake at redhat.com
Thu Apr 25 20:48:08 UTC 2013
On 04/25/2013 02:41 PM, Laine Stump wrote:
> On 04/25/2013 04:30 PM, Eric Blake wrote:
>> POSIX says that both basename() and dirname() may return static
>> storage (aka they are not thread-safe); and that they may but
>> not must modify their input argument. Furthermore, <libgen.h>
>> is not available on all platforms. For these reasons, you should
>> never use these functions in a multi-threaded library.
>>
>> Gnulib instead recommends a way to avoid the portability nightmare:
>> gnulib's "dirname.h" provides useful counterparts. The obvious
>> dir_name() and base_name() are GPL (because they malloc(), but call
>> exit() on failure) so we can't use them; but the LGPL variants
>> mdir_name() (malloc's or returns NULL) and last_component (always
>> points into the incoming string without modifying it, differing
>> from basename semantics only on corner cases like the empty string
>> that we shouldn't be hitting in the first place) are already in use
>> in libvirt. This finishes the swap over to the safe functions.
>>
>
> ACK. Thanks!
Now pushed.
--
Eric Blake eblake 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: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130425/f802d5cd/attachment-0001.sig>
More information about the libvir-list
mailing list