X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fconfigfile.c;h=7e06baa2c83b7eaeb78005fd545105119848d64e;hb=96e0f2341bace029acefe0a88bab96ae326c0ff5;hp=ac5e8edcb94f2bfda66c5eefab67dfab3c66e6db;hpb=7285e5f59ffa4efb391485fe9b35ee02f3dc856f;p=collectd.git diff --git a/src/configfile.c b/src/configfile.c index ac5e8edc..7e06baa2 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -476,6 +476,12 @@ static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src, /* Resize the memory containing the children to be big enough to hold * all children. */ + if (dst->children_num + src->children_num - 1 == 0) + { + dst->children_num = 0; + return (0); + } + temp = (oconfig_item_t *) realloc (dst->children, sizeof (oconfig_item_t) * (dst->children_num + src->children_num - 1)); @@ -587,10 +593,11 @@ static int cf_include_all (oconfig_item_t *root, int depth) sfree (pattern); if (new == NULL) - continue; + return (-1); /* Now replace the i'th child in `root' with `new'. */ - cf_ci_replace_child (root, new, i); + if (cf_ci_replace_child (root, new, i) < 0) + return (-1); /* ... and go back to the new i'th child. */ --i; @@ -606,6 +613,7 @@ static oconfig_item_t *cf_read_file (const char *file, const char *pattern, int depth) { oconfig_item_t *root; + int status; assert (depth < CF_MAX_DEPTH); @@ -637,7 +645,12 @@ static oconfig_item_t *cf_read_file (const char *file, return (NULL); } - cf_include_all (root, depth); + status = cf_include_all (root, depth); + if (status != 0) + { + oconfig_free (root); + return (NULL); + } return (root); } /* oconfig_item_t *cf_read_file */ @@ -830,12 +843,6 @@ static oconfig_item_t *cf_read_generic (const char *path, wordfree (&we); - if (root->children == NULL) - { - oconfig_free (root); - return (NULL); - } - return (root); } /* oconfig_item_t *cf_read_generic */ /* #endif HAVE_WORDEXP_H */ @@ -1047,6 +1054,12 @@ int cf_read (char *filename) ERROR ("Unable to read config file %s.", filename); return (-1); } + else if (conf->children_num == 0) + { + ERROR ("Configuration file %s is empty.", filename); + oconfig_free (conf); + return (-1); + } for (i = 0; i < conf->children_num; i++) {