]> sourceware.org Git - lvm2.git/commitdiff
device_mapper: solve no devices path
authorZdenek Kabelac <zkabelac@redhat.com>
Mon, 27 May 2024 16:13:47 +0000 (18:13 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 27 May 2024 19:33:59 +0000 (21:33 +0200)
Malloc needs to use sane value when names would be NULL.
Also for devices without 'uuid' return empty string instead of NULL.

device_mapper/ioctl/libdm-iface.c

index 62fb37ef94ed193b89d182e30ff69b1123074fc4..170e9c931bf1203d2d7dc45373d2d545e4214611 100644 (file)
@@ -839,7 +839,7 @@ int dm_task_get_device_list(struct dm_task *dmt, struct dm_list **devs_list,
 
        /* buffer for devs +  sorted ptrs + dm_devs + aligned strings */
        if (!(devs = malloc(sizeof(*devs) + cnt * (2 * sizeof(void*) + sizeof(*dm_dev)) +
-                           (char*)names1 - (char*)names + 256)))
+                           (!cnt ? 0 : (char*)names1 - (char*)names + 256))))
                return_0;
 
        dm_list_init(&devs->list);
@@ -958,7 +958,7 @@ int dm_device_list_find_by_dev(const struct dm_list *devs_list,
        if ((dm_dev_found = bsearch(findme, devs->sorted, devs->count, sizeof(void*),
                                    _dm_dev_compare))) {
                fname = (*dm_dev_found)->name;
-               fuuid = (*dm_dev_found)->uuid;
+               fuuid = (*dm_dev_found)->uuid ? : ""; /* Device without UUID */
                ret = 1;
        }
 
This page took 0.052906 seconds and 5 git commands to generate.