From a0ca2c11ee69b51a99644955cb4daa8ca50c8034 Mon Sep 17 00:00:00 2001 From: Alasdair G Kergon Date: Wed, 18 Sep 2013 01:13:06 +0100 Subject: [PATCH] libdm: avoid leak if dm_task_set_* fn called again (Mikulas) --- WHATS_NEW_DM | 1 + libdm/ioctl/libdm-iface.c | 3 +++ libdm/libdm-common.c | 1 + 3 files changed, 5 insertions(+) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index f5d7dc2d9..252f105cf 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.80 - ================================== + Free any previously-set string if a dm_task_set_* function is called again. Do not allow passing empty new name for dmsetup rename. Display any output returned by 'dmsetup message'. Add dm_task_get_message_response to libdevmapper. diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index b0a2228cc..c530bb79a 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -785,6 +785,7 @@ int dm_task_set_newuuid(struct dm_task *dmt, const char *newuuid) newuuid = mangled_uuid; } + dm_free(dmt->newname); if (!(dmt->newname = dm_strdup(newuuid))) { log_error("dm_task_set_newuuid: strdup(%s) failed", newuuid); return 0; @@ -796,6 +797,7 @@ int dm_task_set_newuuid(struct dm_task *dmt, const char *newuuid) int dm_task_set_message(struct dm_task *dmt, const char *message) { + dm_free(dmt->message); if (!(dmt->message = dm_strdup(message))) { log_error("dm_task_set_message: strdup failed"); return 0; @@ -814,6 +816,7 @@ int dm_task_set_sector(struct dm_task *dmt, uint64_t sector) int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, const char *sectors, const char *start) { + dm_free(dmt->geometry); if (dm_asprintf(&(dmt->geometry), "%s %s %s %s", cylinders, heads, sectors, start) < 0) { log_error("dm_task_set_geometry: sprintf failed"); diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index c0669cbd5..b66911c81 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -720,6 +720,7 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname) newname = mangled_name; } + dm_free(dmt->newname); if (!(dmt->newname = dm_strdup(newname))) { log_error("dm_task_set_newname: strdup(%s) failed", newname); return 0;