From fbdd26a4a3c331d04cce83550ccd954aea5e4067 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 27 May 2024 18:13:47 +0200 Subject: [PATCH] device_mapper: solve no devices path 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c index 62fb37ef9..170e9c931 100644 --- a/device_mapper/ioctl/libdm-iface.c +++ b/device_mapper/ioctl/libdm-iface.c @@ -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; }