[collectd] [PATCH] configfile.c: Fixed a segfault after a parse error.

Sebastian Harl sh at tokkee.org
Thu Mar 20 11:00:37 CET 2008


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 at tokkee.org>
---
 src/configfile.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/configfile.c b/src/configfile.c
index ce4e774..18c82d9 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);
-- 
1.5.4.3.325.g6d216

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080320/22976ed8/attachment.pgp 


More information about the collectd mailing list