mirror of
https://github.com/php/php-src.git
synced 2024-12-15 04:45:03 +08:00
MFB: fix crash in tidy_get_body() and related functions when the node doesnt exist
This commit is contained in:
parent
6d5fce416f
commit
c891118ce9
28
ext/tidy/tests/029.phpt
Normal file
28
ext/tidy/tests/029.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
tidy_get_body() crash
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded('tidy')) die('skip'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
// bug report taken from http://news.php.net/php.notes/130628
|
||||
|
||||
$inputs = array(
|
||||
'<frameset > </frameset>',
|
||||
'<html><frameset> </frameset> </html',
|
||||
);
|
||||
|
||||
|
||||
foreach ($inputs as $input) {
|
||||
|
||||
$t = tidy_parse_string($input);
|
||||
$t->cleanRepair();
|
||||
var_dump(tidy_get_body($t));
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
NULL
|
||||
NULL
|
||||
Done
|
@ -902,11 +902,34 @@ static void *php_tidy_get_opt_val(PHPTidyDoc *ptdoc, TidyOption opt, TidyOptionT
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetypes node)
|
||||
static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetypes node_type)
|
||||
{
|
||||
PHPTidyObj *newobj;
|
||||
TidyNode node;
|
||||
TIDY_FETCH_OBJECT;
|
||||
|
||||
switch (node_type) {
|
||||
case is_root_node:
|
||||
node = tidyGetRoot(obj->ptdoc->doc);
|
||||
break;
|
||||
|
||||
case is_html_node:
|
||||
node = tidyGetHtml(obj->ptdoc->doc);
|
||||
break;
|
||||
|
||||
case is_head_node:
|
||||
node = tidyGetHead(obj->ptdoc->doc);
|
||||
break;
|
||||
|
||||
case is_body_node:
|
||||
node = tidyGetBody(obj->ptdoc->doc);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!node) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
tidy_instanciate(tidy_ce_node, return_value TSRMLS_CC);
|
||||
newobj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC);
|
||||
newobj->type = is_node;
|
||||
@ -915,24 +938,6 @@ static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetyp
|
||||
newobj->converter = obj->converter;
|
||||
if (obj->converter) obj->converter->ref_count++;
|
||||
|
||||
switch(node) {
|
||||
case is_root_node:
|
||||
newobj->node = tidyGetRoot(newobj->ptdoc->doc);
|
||||
break;
|
||||
|
||||
case is_html_node:
|
||||
newobj->node = tidyGetHtml(newobj->ptdoc->doc);
|
||||
break;
|
||||
|
||||
case is_head_node:
|
||||
newobj->node = tidyGetHead(newobj->ptdoc->doc);
|
||||
break;
|
||||
|
||||
case is_body_node:
|
||||
newobj->node = tidyGetBody(newobj->ptdoc->doc);
|
||||
break;
|
||||
}
|
||||
|
||||
tidy_add_default_properties(newobj, is_node TSRMLS_CC);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user