From: Sebastian Harl Date: Thu, 20 Mar 2008 10:00:37 +0000 (+0100) Subject: configfile.c: Fixed a segfault after a parse error. X-Git-Tag: collectd-4.3.2~15 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=5cc8977fa83ad48de503b0e7d4b3af39f905dce6;p=collectd.git configfile.c: Fixed a segfault after a parse error. In cf_read_generic(), the parse result had not been checked to not be NULL, which caused a segfault when trying to access any of its members. Now, an error will be returned in that case. Also, cf_ci_append_children() has been made more robust in that respect. It now detects an empty source and does nothing in that case. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/src/configfile.c b/src/configfile.c index ce4e7747..18c82d94 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -423,6 +423,9 @@ static int cf_ci_append_children (oconfig_item_t *dst, oconfig_item_t *src) { oconfig_item_t *temp; + if ((src == NULL) || (src->children_num == 0)) + return (0); + temp = (oconfig_item_t *) realloc (dst->children, sizeof (oconfig_item_t) * (dst->children_num + src->children_num)); @@ -628,6 +631,11 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth) continue; } + if (temp == NULL) { + oconfig_free (root); + return (NULL); + } + cf_ci_append_children (root, temp); sfree (temp->children); sfree (temp);