fix a crash when tag could be uninitialized and not set to a fixed buffer tagname - webdump - HTML to plain-text converter for webpages
(HTM) git clone git://git.codemadness.org/webdump
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 115f7e68eeccd7f1030fc631c52bab35692c6973
(DIR) parent 64010b2be4bc3845ef07db25f8621c7894fe64bb
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 22 May 2024 19:12:44 +0200
fix a crash when tag could be uninitialized and not set to a fixed buffer tagname
Reported by pi31415 when he was testing webdump on a binary ZIP file, thanks!
Diffstat:
M webdump.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
---
(DIR) diff --git a/webdump.c b/webdump.c
@@ -1540,6 +1540,8 @@ printlinkrefs(void)
static void
incnode(void)
{
+ size_t i;
+
curnode++;
if (curnode >= MAX_NODE_DEPTH)
@@ -1553,6 +1555,11 @@ incnode(void)
memset(&nodes[ncapnodes], 0, sizeof(*nodes) * NODE_CAP_INC);
memset(&nodes_links[ncapnodes], 0, sizeof(*nodes_links) * NODE_CAP_INC);
+ for (i = ncapnodes; i < ncapnodes + NODE_CAP_INC; i++) {
+ nodes[i].tag.displaytype = DisplayInline;
+ nodes[i].tag.name = nodes[i].tagname; /* assign to use fixed-size buffer */
+ }
+
ncapnodes += NODE_CAP_INC; /* greedy alloc */
}
}
@@ -1987,8 +1994,6 @@ xmltagstart(XMLParser *p, const char *t, size_t tl)
cur = &nodes[curnode];
memset(cur, 0, sizeof(*cur)); /* clear / reset node */
/* tag defaults */
- cur->tag.displaytype = DisplayInline;
- cur->tag.name = cur->tagname; /* assign fixed-size buffer */
strlcpy(cur->tagname, t, sizeof(cur->tagname));
/* force to lowercase */
@@ -2416,9 +2421,6 @@ main(int argc, char **argv)
nodes = ecalloc(ncapnodes, sizeof(*nodes));
nodes_links = ecalloc(ncapnodes, sizeof(*nodes_links));
- /* top-most document root needs initialization */
- nodes[0].tag.name = "";
-
parser.xmlattrstart = xmlattrstart;
parser.xmlattr = xmlattr;
parser.xmlattrentity = xmlattrentity;