Skip to content

Commit

Permalink
Fix a crash bug with empty titles (Issue #425)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed May 7, 2021
1 parent ca282d0 commit a0014be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fixed crash bugs with bogus table attributes (Issue #416, Issue #417)
- Fixed a crash bug with malformed URIs (Issue #418)
- Fixed a crash bug with malformed GIF files (Issue #423)
- Fixed a crash bug with empty titles (Issue #425)
- Fixed some issues reported by Coverity.
- Removed the bundled libjpeg, libpng, and zlib.

Expand Down
18 changes: 9 additions & 9 deletions htmldoc/htmllib.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* HTML parsing routines for HTMLDOC, a HTML document processing program.
*
* Copyright 2011-2020 by Michael R Sweet.
* Copyright 2011-2021 by Michael R Sweet.
* Copyright 1997-2010 by Easy Software Products. All rights reserved.
*
* This program is free software. Distribution and use rights are outlined in
Expand Down Expand Up @@ -2114,11 +2114,11 @@ htmlGetText(tree_t *t) /* I - Tree to pick */
else
tdata = t->data;

if (tdata != NULL)
tlen = tdata ? strlen((char *)tdata) : 0;

if (tdata != NULL && tlen > 0)
{
// Add the text to this string...
tlen = strlen((char *)tdata);

if (s)
s2 = (uchar *)realloc(s, 1 + slen + tlen);
else
Expand All @@ -2132,12 +2132,12 @@ htmlGetText(tree_t *t) /* I - Tree to pick */
memcpy((char *)s + slen, (char *)tdata, tlen);

slen += tlen;
}

if (talloc)
{
free(talloc);
talloc = NULL;
}
if (talloc)
{
free(talloc);
talloc = NULL;
}

t = t->next;
Expand Down
11 changes: 10 additions & 1 deletion htmldoc/testhtml.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,21 @@ static void
show_tree(tree_t *t, /* I - Parent node */
int indent) /* I - Indentation */
{
static const char * const markups[] =
{
"FILE",
"UNKNOWN",
"ERROR"
};

while (t)
{
if (t->markup == MARKUP_NONE)
printf("%*s\"%s\"\n", indent, "", t->data);
else
else if (t->markup > MARKUP_NONE)
printf("%*s%s\n", indent, "", _htmlMarkups[t->markup]);
else
printf("%*s%s\n", indent, "", markups[t->markup - MARKUP_FILE]);

if (t->child)
show_tree(t->child, indent + 2);
Expand Down

0 comments on commit a0014be

Please sign in to comment.