summaryrefslogtreecommitdiff
path: root/ext/xsl/xsltprocessor.c
diff options
context:
space:
mode:
authorMáté Kocsis <kocsismate@woohoolabs.com>2020-08-24 20:42:29 +0200
committerMáté Kocsis <kocsismate@woohoolabs.com>2020-09-02 11:11:38 +0200
commit3e800e997bddc29cd28924c44846f7d2133a8933 (patch)
treee650686b950164531a16af82642dd52b826fb1d3 /ext/xsl/xsltprocessor.c
parentddc2a2d381843e086fc36388981d0b8ba1ea789d (diff)
downloadphp-git-3e800e997bddc29cd28924c44846f7d2133a8933.tar.gz
Move custom type checks to ZPP
Closes GH-6034
Diffstat (limited to 'ext/xsl/xsltprocessor.c')
-rw-r--r--ext/xsl/xsltprocessor.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c
index 29b3ff5fb3..26edbb9045 100644
--- a/ext/xsl/xsltprocessor.c
+++ b/ext/xsl/xsltprocessor.c
@@ -666,21 +666,35 @@ PHP_METHOD(XSLTProcessor, setParameter)
{
zval *id = ZEND_THIS;
- zval *array_value, *entry, new_string;
+ zval *entry, new_string;
+ HashTable *array_value;
xsl_object *intern;
char *namespace;
size_t namespace_len;
- zend_string *string_key, *name, *value;
+ zend_string *string_key, *name, *value = NULL;
+
+ ZEND_PARSE_PARAMETERS_START(2, 3)
+ Z_PARAM_STRING(namespace, namespace_len)
+ Z_PARAM_STR_OR_ARRAY_HT(name, array_value)
+ Z_PARAM_OPTIONAL
+ Z_PARAM_STR_OR_NULL(value)
+ ZEND_PARSE_PARAMETERS_END();
+
+ intern = Z_XSL_P(id);
+
+ if (array_value) {
+ if (value) {
+ zend_argument_value_error(3, "must be null when argument #2 ($name) is an array");
+ RETURN_THROWS();
+ }
- if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "sa", &namespace, &namespace_len, &array_value) == SUCCESS) {
- intern = Z_XSL_P(id);
- ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array_value), string_key, entry) {
+ ZEND_HASH_FOREACH_STR_KEY_VAL(array_value, string_key, entry) {
zval tmp;
zend_string *str;
if (string_key == NULL) {
- php_error_docref(NULL, E_WARNING, "Invalid parameter array");
- RETURN_FALSE;
+ zend_argument_type_error(2, "must contain only string keys");
+ RETURN_THROWS();
}
str = zval_try_get_string(entry);
if (UNEXPECTED(!str)) {
@@ -690,18 +704,17 @@ PHP_METHOD(XSLTProcessor, setParameter)
zend_hash_update(intern->parameter, string_key, &tmp);
} ZEND_HASH_FOREACH_END();
RETURN_TRUE;
- } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "sSS", &namespace, &namespace_len, &name, &value) == SUCCESS) {
-
- intern = Z_XSL_P(id);
+ } else {
+ if (!value) {
+ zend_argument_value_error(3, "cannot be null when argument #2 ($name) is a string");
+ RETURN_THROWS();
+ }
ZVAL_STR_COPY(&new_string, value);
zend_hash_update(intern->parameter, name, &new_string);
RETURN_TRUE;
- } else {
- WRONG_PARAM_COUNT;
}
-
}
/* }}} end XSLTProcessor::setParameter */