From ef8e6cfce7cb2b1c39dc31108f535a6f592b558d Mon Sep 17 00:00:00 2001 From: Leonardo Taccari Date: Thu, 12 Mar 2020 22:33:53 +0100 Subject: [PATCH] handle closed tag with no corresponding open tag (for malformed HTML) This avoid possible NULL pointer dereference, e.g. when just parsing `'. --- webdump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webdump.c b/webdump.c index ad018f2..9577ab2 100644 --- a/webdump.c +++ b/webdump.c @@ -672,7 +672,8 @@ xmltagend(XMLParser *p, const char *t, size_t tl, int isshort) } /* if the current closing tag matches the current open tag */ - if (!strcasecmp(nodes[curnode].tag.name, t)) { + if (nodes[curnode].tag.name && + !strcasecmp(nodes[curnode].tag.name, t)) { tagend(&nodes[curnode]); if (curnode) curnode--; @@ -680,7 +681,8 @@ xmltagend(XMLParser *p, const char *t, size_t tl, int isshort) /* ... else lookup the first matching start tag. This is also for handling optional closing tags */ for (i = curnode; i > 0; i--) { - if (!strcasecmp(nodes[i].tag.name, t)) { + if (nodes[curnode].tag.name && + !strcasecmp(nodes[i].tag.name, t)) { tagend(&nodes[i]); curnode = i; break; -- 2.25.1