From 2a2487f02fb2ddb72106f922dcbf0ddda6959b2f Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 16 Nov 2015 13:07:36 +0100 Subject: [PATCH] libdm: better error reporting from dm_split_lvm_name Report errors from all error paths correctly. Validate passed args before dereferencing them. --- libdm/libdm-string.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c index 913283283..79a969ce3 100644 --- a/libdm/libdm-string.c +++ b/libdm/libdm-string.c @@ -95,13 +95,18 @@ static char *_unquote(char *component) int dm_split_lvm_name(struct dm_pool *mem, const char *dmname, char **vgname, char **lvname, char **layer) { - if (mem && !(*vgname = dm_pool_strdup(mem, dmname))) { - log_error("Failed to duplicate dmname."); + if (!vgname || !lvname || !layer) { + log_error(INTERNAL_ERROR "dm_split_lvm_name: vgname, lvname nor layer could be NULL."); return 0; } - if (!*vgname) + if (mem && (!dmname || !(*vgname = dm_pool_strdup(mem, dmname)))) { + log_error("Failed to duplicate lvm name."); return 0; + } else if (!*vgname) { + log_error("Missing lvm name for split."); + return 0; + } _unquote(*layer = _unquote(*lvname = _unquote(*vgname)));