• E
    build: avoid unsafe functions in libgen.h · 1fbf1905
    Eric Blake 提交于
    POSIX says that both basename() and dirname() may return static
    storage (aka they need not be 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 thread-safe 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.
    
    * cfg.mk (sc_prohibit_libgen): New rule.
    * src/util/vircgroup.c: Fix offenders.
    * src/parallels/parallels_storage.c (parallelsPoolAddByDomain):
    Likewise.
    * src/parallels/parallels_network.c (parallelsGetBridgedNetInfo):
    Likewise.
    * src/node_device/node_device_udev.c (udevProcessSCSIHost)
    (udevProcessSCSIDevice): Likewise.
    * src/storage/storage_backend_disk.c
    (virStorageBackendDiskDeleteVol): Likewise.
    * src/util/virpci.c (virPCIGetDeviceAddressFromSysfsLink):
    Likewise.
    * src/util/virstoragefile.h (_virStorageFileMetadata): Avoid false
    positive.
    Signed-off-by: NEric Blake <eblake@redhat.com>
    1fbf1905
storage_backend_disk.c 26.1 KB