Skip to content

Commit 5ebe04d

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Don't crash on uninitialized tidy object
2 parents 393264a + 6de6f2a commit 5ebe04d

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

ext/tidy/tests/uninitialized.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Operations on uninitialized tidy object
3+
--SKIPIF--
4+
<?php if (!extension_loaded("tidy")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
$tidy = new tidy;
9+
try {
10+
var_dump($tidy->getHtmlVer());
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
try {
15+
var_dump($tidy->isXhtml());
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
try {
20+
var_dump($tidy->isXml());
21+
} catch (Error $e) {
22+
echo $e->getMessage(), "\n";
23+
}
24+
25+
?>
26+
--EXPECT--
27+
tidy object is not initialized
28+
tidy object is not initialized
29+
tidy object is not initialized

ext/tidy/tidy.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
} \
6060
obj = Z_TIDY_P(object); \
6161

62+
#define TIDY_FETCH_INITIALIZED_OBJECT \
63+
TIDY_FETCH_OBJECT; \
64+
if (!obj->ptdoc->initialized) { \
65+
zend_throw_error(NULL, "tidy object is not initialized"); \
66+
return; \
67+
}
68+
6269
#define TIDY_FETCH_ONLY_OBJECT \
6370
PHPTidyObj *obj; \
6471
TIDY_SET_CONTEXT; \
@@ -1229,7 +1236,7 @@ PHP_FUNCTION(tidy_get_status)
12291236
/* {{{ Get the Detected HTML version for the specified document. */
12301237
PHP_FUNCTION(tidy_get_html_ver)
12311238
{
1232-
TIDY_FETCH_OBJECT;
1239+
TIDY_FETCH_INITIALIZED_OBJECT;
12331240

12341241
RETURN_LONG(tidyDetectedHtmlVersion(obj->ptdoc->doc));
12351242
}
@@ -1238,7 +1245,7 @@ PHP_FUNCTION(tidy_get_html_ver)
12381245
/* {{{ Indicates if the document is a XHTML document. */
12391246
PHP_FUNCTION(tidy_is_xhtml)
12401247
{
1241-
TIDY_FETCH_OBJECT;
1248+
TIDY_FETCH_INITIALIZED_OBJECT;
12421249

12431250
RETURN_BOOL(tidyDetectedXhtml(obj->ptdoc->doc));
12441251
}
@@ -1247,7 +1254,7 @@ PHP_FUNCTION(tidy_is_xhtml)
12471254
/* {{{ Indicates if the document is a generic (non HTML/XHTML) XML document. */
12481255
PHP_FUNCTION(tidy_is_xml)
12491256
{
1250-
TIDY_FETCH_OBJECT;
1257+
TIDY_FETCH_INITIALIZED_OBJECT;
12511258

12521259
RETURN_BOOL(tidyDetectedGenericXml(obj->ptdoc->doc));
12531260
}

0 commit comments

Comments
 (0)