thandle closed tag with no corresponding open tag (for malformed HTML) - webdump - [FORK] git://git.codemadness.org/webdump
 (HTM) git clone git://git.z3bra.org/webdump.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 1ccfc4c151797ab36eaa37d0b84e9c12236af6c3
 (DIR) parent 6675aae92b4d75ad0b40216faf66db996fd298e4
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Thu, 12 Mar 2020 22:33:53 +0100
       
       handle closed tag with no corresponding open tag (for malformed HTML)
       
       This avoid possible NULL pointer dereference, e.g. when just parsing
       `</a>'.
       
       Diffstat:
         M webdump.c                           |       6 ++++--
       
       1 file changed, 4 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/webdump.c b/webdump.c
       t@@ -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--;
       t@@ -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;