changeset 18583:cf7297803a73

Guard against possible weird crashes.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 21 Jul 2007 05:53:05 +0000
parents 882ea30935a9
children 91fdd3e4892f 66f2354fb0fd c7a5cd17b045
files finch/libgnt/gntutils.c
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntutils.c	Sat Jul 21 05:47:46 2007 +0000
+++ b/finch/libgnt/gntutils.c	Sat Jul 21 05:53:05 2007 +0000
@@ -234,7 +234,7 @@
 
 #ifndef NO_LIBXML
 static GntWidget *
-gnt_widget_from_xmlnode(xmlNode *node, GntWidget **data[])
+gnt_widget_from_xmlnode(xmlNode *node, GntWidget **data[], int max)
 {
 	GntWidget *widget = NULL;
 	char *name;
@@ -284,7 +284,7 @@
 		}
 
 		for (ch = node->children; ch; ch=ch->next)
-			gnt_box_add_widget(GNT_BOX(widget), gnt_widget_from_xmlnode(ch, data));
+			gnt_box_add_widget(GNT_BOX(widget), gnt_widget_from_xmlnode(ch, data, max));
 	} else if (strcmp(name, "button") == 0) {
 		widget = gnt_button_new(content);
 	} else if (strcmp(name, "label") == 0) {
@@ -313,9 +313,10 @@
 	id = (char*)xmlGetProp(node, (xmlChar*)"id");
 	if (id) {
 		int i;
-		sscanf(id, "%d", &i);
-		*data[i] = widget;
-		xmlFree(id);
+		if (sscanf(id, "%d", &i) == 1 && i >= 0 && i < max) {
+			*data[i] = widget;
+			xmlFree(id);
+		}
 	}
 
 	prop = (char*)xmlGetProp(node, (xmlChar*)"border");
@@ -366,7 +367,7 @@
 		data[id] = va_arg(list, gpointer);
 
 	node = xmlDocGetRootElement(doc);
-	gnt_widget_from_xmlnode(node, data);
+	gnt_widget_from_xmlnode(node, data, num);
 
 	xmlFreeDoc(doc);
 	xmlCleanupParser();