Skip to content

Commit 85d9a1c

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Don't crash on uninitialized tidy object
2 parents 4ea01bd + d4bf079 commit 85d9a1c

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
@@ -66,6 +66,13 @@
6666
} \
6767
obj = Z_TIDY_P(object); \
6868

69+
#define TIDY_FETCH_INITIALIZED_OBJECT \
70+
TIDY_FETCH_OBJECT; \
71+
if (!obj->ptdoc->initialized) { \
72+
zend_throw_error(NULL, "tidy object is not initialized"); \
73+
return; \
74+
}
75+
6976
#define TIDY_FETCH_ONLY_OBJECT \
7077
PHPTidyObj *obj; \
7178
TIDY_SET_CONTEXT; \
@@ -1486,7 +1493,7 @@ static PHP_FUNCTION(tidy_get_status)
14861493
Get the Detected HTML version for the specified document. */
14871494
static PHP_FUNCTION(tidy_get_html_ver)
14881495
{
1489-
TIDY_FETCH_OBJECT;
1496+
TIDY_FETCH_INITIALIZED_OBJECT;
14901497

14911498
RETURN_LONG(tidyDetectedHtmlVersion(obj->ptdoc->doc));
14921499
}
@@ -1496,7 +1503,7 @@ static PHP_FUNCTION(tidy_get_html_ver)
14961503
Indicates if the document is a XHTML document. */
14971504
static PHP_FUNCTION(tidy_is_xhtml)
14981505
{
1499-
TIDY_FETCH_OBJECT;
1506+
TIDY_FETCH_INITIALIZED_OBJECT;
15001507

15011508
RETURN_BOOL(tidyDetectedXhtml(obj->ptdoc->doc));
15021509
}
@@ -1506,7 +1513,7 @@ static PHP_FUNCTION(tidy_is_xhtml)
15061513
Indicates if the document is a generic (non HTML/XHTML) XML document. */
15071514
static PHP_FUNCTION(tidy_is_xml)
15081515
{
1509-
TIDY_FETCH_OBJECT;
1516+
TIDY_FETCH_INITIALIZED_OBJECT;
15101517

15111518
RETURN_BOOL(tidyDetectedGenericXml(obj->ptdoc->doc));
15121519
}

0 commit comments

Comments
 (0)