Code

configfile.c: Fixed a segfault after a parse error.
authorSebastian Harl <sh@tokkee.org>
Thu, 20 Mar 2008 10:00:37 +0000 (11:00 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Sat, 22 Mar 2008 08:30:27 +0000 (09:30 +0100)
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 <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/configfile.c

index ce4e7747c95af39aee1f55c9bf1479c2c3917da9..18c82d945a866098ec43016c87364f20da5468cd 100644 (file)
@@ -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);