diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2012-12-14 01:00:36 +0100 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2012-12-15 17:23:26 +0100 |
commit | 788ac7fa547fb98f0edd38685d40b80609f298dc (patch) | |
tree | 3b880d98565d80de373c8117b056d2bc3fd73b9c /libdaemon | |
parent | ff5612c0c3208276763348e9f9afa9a09096fbe1 (diff) | |
download | lvm2-788ac7fa547fb98f0edd38685d40b80609f298dc.tar.gz |
libdaemon: check for strdup result
Detect failure of dm_pool_strdup() and print error in fail path.
Save one extra strchr call - since we already know the distance
for the '=' character.
Drop stack trace from return after log_error().
Diffstat (limited to 'libdaemon')
-rw-r--r-- | libdaemon/client/config-util.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/libdaemon/client/config-util.c b/libdaemon/client/config-util.c index 1c8313436..34d755fae 100644 --- a/libdaemon/client/config-util.c +++ b/libdaemon/client/config-util.c @@ -215,7 +215,8 @@ struct dm_config_node *config_make_nodes_v(struct dm_config_tree *cft, const char *next; struct dm_config_node *first = NULL; struct dm_config_node *cn; - const char *fmt, *key; + const char *fmt; + char *key; while ((next = va_arg(ap, char *))) { cn = NULL; @@ -223,12 +224,16 @@ struct dm_config_node *config_make_nodes_v(struct dm_config_tree *cft, if (!fmt) { log_error(INTERNAL_ERROR "Bad format string '%s'", fmt); - return_NULL; + return NULL; + } + + if (!(key = dm_pool_strdup(cft->mem, next))) { + log_error("Failed to duplicate node key."); + return NULL; } - fmt += 2; - key = dm_pool_strdup(cft->mem, next); - *strchr(key, '=') = 0; + key[fmt - next] = '\0'; + fmt += 2; if (!strcmp(fmt, "%d") || !strcmp(fmt, "%" PRId64)) { int64_t value = va_arg(ap, int64_t); @@ -247,7 +252,7 @@ struct dm_config_node *config_make_nodes_v(struct dm_config_tree *cft, chain_node(cn, parent, pre_sib); } else { log_error(INTERNAL_ERROR "Bad format string '%s'", fmt); - return_NULL; + return NULL; } if (!first) first = cn; |