diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-22 16:04:22 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-22 16:04:22 +0200 |
commit | d4bf0799b80d8bbd128e9e41624779d844033a42 (patch) | |
tree | 1bd5d382c32558ef9d5e2cb8158033fcb67b21da /ext/tidy/tidy.c | |
parent | d4200ba6cfd6909265643516e658560502caec70 (diff) | |
download | php-git-d4bf0799b80d8bbd128e9e41624779d844033a42.tar.gz |
Don't crash on uninitialized tidy object
"Uninitialized" here means that the object was created ordinarily
-- no constructor skipping involved. Most tidy methods seem to
handle this fine, but these three need to be guarded.
Diffstat (limited to 'ext/tidy/tidy.c')
-rw-r--r-- | ext/tidy/tidy.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index 60170585ce..34fe525a1e 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -66,6 +66,13 @@ } \ 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 \ PHPTidyObj *obj; \ TIDY_SET_CONTEXT; \ @@ -1474,7 +1481,7 @@ static PHP_FUNCTION(tidy_get_status) Get the Detected HTML version for the specified document. */ static PHP_FUNCTION(tidy_get_html_ver) { - TIDY_FETCH_OBJECT; + TIDY_FETCH_INITIALIZED_OBJECT; RETURN_LONG(tidyDetectedHtmlVersion(obj->ptdoc->doc)); } @@ -1484,7 +1491,7 @@ static PHP_FUNCTION(tidy_get_html_ver) Indicates if the document is a XHTML document. */ static PHP_FUNCTION(tidy_is_xhtml) { - TIDY_FETCH_OBJECT; + TIDY_FETCH_INITIALIZED_OBJECT; RETURN_BOOL(tidyDetectedXhtml(obj->ptdoc->doc)); } @@ -1494,7 +1501,7 @@ static PHP_FUNCTION(tidy_is_xhtml) Indicates if the document is a generic (non HTML/XHTML) XML document. */ static PHP_FUNCTION(tidy_is_xml) { - TIDY_FETCH_OBJECT; + TIDY_FETCH_INITIALIZED_OBJECT; RETURN_BOOL(tidyDetectedGenericXml(obj->ptdoc->doc)); } |