Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Don't crash on uninitialized tidy object
This commit is contained in:
Nikita Popov 2020-10-22 16:05:57 +02:00
commit 6de6f2a4e9
2 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,29 @@
--TEST--
Operations on uninitialized tidy object
--SKIPIF--
<?php if (!extension_loaded("tidy")) print "skip"; ?>
--FILE--
<?php
$tidy = new tidy;
try {
var_dump($tidy->getHtmlVer());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump($tidy->isXhtml());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump($tidy->isXml());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
tidy object is not initialized
tidy object is not initialized
tidy object is not initialized

View File

@ -59,6 +59,13 @@
} \ } \
obj = Z_TIDY_P(object); \ obj = Z_TIDY_P(object); \
#define TIDY_FETCH_INITIALIZED_OBJECT \
TIDY_FETCH_OBJECT; \
if (!obj->ptdoc->initialized) { \
zend_throw_error(NULL, "tidy object is not initialized"); \
return; \
}
#define TIDY_FETCH_ONLY_OBJECT \ #define TIDY_FETCH_ONLY_OBJECT \
PHPTidyObj *obj; \ PHPTidyObj *obj; \
TIDY_SET_CONTEXT; \ TIDY_SET_CONTEXT; \
@ -1229,7 +1236,7 @@ PHP_FUNCTION(tidy_get_status)
/* {{{ Get the Detected HTML version for the specified document. */ /* {{{ Get the Detected HTML version for the specified document. */
PHP_FUNCTION(tidy_get_html_ver) PHP_FUNCTION(tidy_get_html_ver)
{ {
TIDY_FETCH_OBJECT; TIDY_FETCH_INITIALIZED_OBJECT;
RETURN_LONG(tidyDetectedHtmlVersion(obj->ptdoc->doc)); RETURN_LONG(tidyDetectedHtmlVersion(obj->ptdoc->doc));
} }
@ -1238,7 +1245,7 @@ PHP_FUNCTION(tidy_get_html_ver)
/* {{{ Indicates if the document is a XHTML document. */ /* {{{ Indicates if the document is a XHTML document. */
PHP_FUNCTION(tidy_is_xhtml) PHP_FUNCTION(tidy_is_xhtml)
{ {
TIDY_FETCH_OBJECT; TIDY_FETCH_INITIALIZED_OBJECT;
RETURN_BOOL(tidyDetectedXhtml(obj->ptdoc->doc)); RETURN_BOOL(tidyDetectedXhtml(obj->ptdoc->doc));
} }
@ -1247,7 +1254,7 @@ PHP_FUNCTION(tidy_is_xhtml)
/* {{{ Indicates if the document is a generic (non HTML/XHTML) XML document. */ /* {{{ Indicates if the document is a generic (non HTML/XHTML) XML document. */
PHP_FUNCTION(tidy_is_xml) PHP_FUNCTION(tidy_is_xml)
{ {
TIDY_FETCH_OBJECT; TIDY_FETCH_INITIALIZED_OBJECT;
RETURN_BOOL(tidyDetectedGenericXml(obj->ptdoc->doc)); RETURN_BOOL(tidyDetectedGenericXml(obj->ptdoc->doc));
} }