From 3673e07cff6ec05b1662972dd7b1b68a92e68301 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Thu, 3 Jun 2010 21:59:18 +0000 Subject: [PATCH] * Store the root XML element when parsing, and make sure we don't write to memory we shouldn't be writing to. --- upnpreplyparse.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/upnpreplyparse.c b/upnpreplyparse.c index 81d5a9f..6ab8fc8 100644 --- a/upnpreplyparse.c +++ b/upnpreplyparse.c @@ -16,10 +16,21 @@ static void NameValueParserStartElt(void * d, const char * name, int l) { struct NameValueParserData * data = (struct NameValueParserData *)d; - if(l>511) - l = 511; + if(l>63) + l = 63; memcpy(data->curelt, name, l); data->curelt[l] = '\0'; + + /* store root element */ + if(!data->head.lh_first) + { + struct NameValue * nv; + nv = malloc(sizeof(struct NameValue)); + strcpy(nv->name, "rootElement"); + memcpy(nv->value, name, l); + nv->value[l] = '\0'; + LIST_INSERT_HEAD( &(data->head), nv, entries); + } } static void @@ -50,7 +61,7 @@ ParseNameValue(const char * buffer, int bufsize, parser.starteltfunc = NameValueParserStartElt; parser.endeltfunc = 0; parser.datafunc = NameValueParserGetData; - parser.attfunc = 0; + parser.attfunc = 0; parsexml(&parser); }