Skip to content

Commit 0584e59

Browse files
committed
tidy: Harden against tidyNodeGetText() failure
Either the buffer size or the return value needs to be checked. From a quick look into the tidy source code, this can't fail right now for our use case in practice, but it might in the future. Closes GH-20389.
1 parent 51edaac commit 0584e59

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

ext/tidy/tidy.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ static zend_result tidy_node_cast_handler(zend_object *in, zval *out, int type)
553553
case IS_STRING:
554554
obj = php_tidy_fetch_object(in);
555555
tidyBufInit(&buf);
556-
if (obj->ptdoc) {
557-
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf);
556+
if (obj->ptdoc && tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf)) {
558557
ZVAL_STRINGL(out, (char *) buf.bp, buf.size-1);
559558
} else {
560559
ZVAL_EMPTY_STRING(out);
@@ -611,7 +610,7 @@ static void tidy_add_node_default_properties(PHPTidyObj *obj)
611610
char *name;
612611

613612
tidyBufInit(&buf);
614-
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf);
613+
(void) tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf);
615614

616615
zend_update_property_stringl(
617616
tidy_ce_node,

0 commit comments

Comments
 (0)