diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-22 16:05:34 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-22 16:05:34 +0200 |
commit | 85d9a1ca6ef00e8de77801bcadf3468aada16b90 (patch) | |
tree | 3e9608a8460a989671af6bcb6b36fb9f3c6eb09a | |
parent | 4ea01bdc67e9e39e18cfe732578647fa2382b3b0 (diff) | |
parent | d4bf0799b80d8bbd128e9e41624779d844033a42 (diff) | |
download | php-git-85d9a1ca6ef00e8de77801bcadf3468aada16b90.tar.gz |
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
Don't crash on uninitialized tidy object
-rw-r--r-- | ext/tidy/tests/uninitialized.phpt | 29 | ||||
-rw-r--r-- | ext/tidy/tidy.c | 13 |
2 files changed, 39 insertions, 3 deletions
diff --git a/ext/tidy/tests/uninitialized.phpt b/ext/tidy/tests/uninitialized.phpt new file mode 100644 index 0000000000..3533f0d345 --- /dev/null +++ b/ext/tidy/tests/uninitialized.phpt @@ -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 diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index bf38faf224..a1a5184dd5 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; \ @@ -1486,7 +1493,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)); } @@ -1496,7 +1503,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)); } @@ -1506,7 +1513,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)); } |