Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,17 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva
}
} else if (cur_arg_info->type_hint) {
switch(cur_arg_info->type_hint) {
case IS_LONG:
if (!arg) {
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type long", "", "none", "" TSRMLS_CC);
}

if (Z_TYPE_P(arg) != IS_LONG && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)
&& (Z_TYPE_P(arg) != IS_STRING || is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), NULL, NULL, 0)) == 0) {
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type long", "", zend_zval_type_name(arg), "" TSRMLS_CC);
}
break;

case IS_ARRAY:
if (!arg) {
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", "none", "" TSRMLS_CC);
Expand Down
18 changes: 12 additions & 6 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_substr, 0, 0, 2)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, length)
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
ZEND_ARG_INFO(0, encoding)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_strcut, 0, 0, 2)
ZEND_ARG_INFO(0, str)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, length)
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
ZEND_ARG_INFO(0, encoding)
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -2714,10 +2714,11 @@ PHP_FUNCTION(mb_substr)
size_t argc = ZEND_NUM_ARGS();
char *str, *encoding;
long from, len;
zval *zlen = NULL;
int mblen, str_len, encoding_len;
mbfl_string string, result, *ret;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", &str, &str_len, &from, &len, &encoding, &encoding_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|z!s", &str, &str_len, &from, &zlen, &encoding, &encoding_len) == FAILURE) {
return;
}

Expand All @@ -2736,8 +2737,10 @@ PHP_FUNCTION(mb_substr)
string.val = (unsigned char *)str;
string.len = str_len;

if (argc < 3) {
if (argc < 3 || !zlen) {
len = str_len;
} else {
len = Z_LVAL_P(zlen);
}

/* measures length */
Expand Down Expand Up @@ -2787,14 +2790,15 @@ PHP_FUNCTION(mb_strcut)
size_t argc = ZEND_NUM_ARGS();
char *encoding;
long from, len;
zval *zlen = NULL;
int encoding_len;
mbfl_string string, result, *ret;

mbfl_string_init(&string);
string.no_language = MBSTRG(language);
string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", (char **)&string.val, (int **)&string.len, &from, &len, &encoding, &encoding_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|z!s", (char **)&string.val, (int **)&string.len, &from, &zlen, &encoding, &encoding_len) == FAILURE) {
return;
}

Expand All @@ -2806,8 +2810,10 @@ PHP_FUNCTION(mb_strcut)
}
}

if (argc < 3) {
if (argc < 3 || !zlen) {
len = string.len;
} else {
len = Z_LVAL_P(zlen);
}

/* if "from" position is negative, count start position from the end
Expand Down
2 changes: 0 additions & 2 deletions ext/mbstring/tests/mb_str_functions_opt-parameter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ baz
baz
foo
==DONE==
--XFAIL--
mb functions fail to allow null instead of actual value