Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix bug #40531 mb_substr optional parameters

To distinguish between null and 0 for an integer parameter,
we have to use the "z!" type instead of "l" in zend_parse_parameters().
So the type checks are now done in the prototype with
ZEND_ARG_TYPE_INFO().

The prototype is more strict than before. An non integer (or a string
that isn't purely numeric) will lead to a fatal error, whereas there was
previously a simple warning.
  • Loading branch information...
commit 0292a6fe94347b8979f37c05baf5dea051ca482a 1 parent 0b63bc5
François Gannaz authored

Showing 1 changed file with 12 additions and 6 deletions. Show diff stats Hide diff stats

  1. +12 6 ext/mbstring/mbstring.c
18 ext/mbstring/mbstring.c
@@ -325,14 +325,14 @@ ZEND_END_ARG_INFO()
325 325 ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_substr, 0, 0, 2)
326 326 ZEND_ARG_INFO(0, str)
327 327 ZEND_ARG_INFO(0, start)
328   - ZEND_ARG_INFO(0, length)
  328 + ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
329 329 ZEND_ARG_INFO(0, encoding)
330 330 ZEND_END_ARG_INFO()
331 331
332 332 ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_strcut, 0, 0, 2)
333 333 ZEND_ARG_INFO(0, str)
334 334 ZEND_ARG_INFO(0, start)
335   - ZEND_ARG_INFO(0, length)
  335 + ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
336 336 ZEND_ARG_INFO(0, encoding)
337 337 ZEND_END_ARG_INFO()
338 338
@@ -2714,10 +2714,11 @@ PHP_FUNCTION(mb_substr)
2714 2714 size_t argc = ZEND_NUM_ARGS();
2715 2715 char *str, *encoding;
2716 2716 long from, len;
  2717 + zval *zlen = NULL;
2717 2718 int mblen, str_len, encoding_len;
2718 2719 mbfl_string string, result, *ret;
2719 2720
2720   - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", &str, &str_len, &from, &len, &encoding, &encoding_len) == FAILURE) {
  2721 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|z!s", &str, &str_len, &from, &zlen, &encoding, &encoding_len) == FAILURE) {
2721 2722 return;
2722 2723 }
2723 2724
@@ -2736,8 +2737,10 @@ PHP_FUNCTION(mb_substr)
2736 2737 string.val = (unsigned char *)str;
2737 2738 string.len = str_len;
2738 2739
2739   - if (argc < 3) {
  2740 + if (argc < 3 || !zlen) {
2740 2741 len = str_len;
  2742 + } else {
  2743 + len = Z_LVAL_P(zlen);
2741 2744 }
2742 2745
2743 2746 /* measures length */
@@ -2787,6 +2790,7 @@ PHP_FUNCTION(mb_strcut)
2787 2790 size_t argc = ZEND_NUM_ARGS();
2788 2791 char *encoding;
2789 2792 long from, len;
  2793 + zval *zlen = NULL;
2790 2794 int encoding_len;
2791 2795 mbfl_string string, result, *ret;
2792 2796
@@ -2794,7 +2798,7 @@ PHP_FUNCTION(mb_strcut)
2794 2798 string.no_language = MBSTRG(language);
2795 2799 string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;
2796 2800
2797   - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", (char **)&string.val, (int **)&string.len, &from, &len, &encoding, &encoding_len) == FAILURE) {
  2801 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|z!s", (char **)&string.val, (int **)&string.len, &from, &zlen, &encoding, &encoding_len) == FAILURE) {
2798 2802 return;
2799 2803 }
2800 2804
@@ -2806,8 +2810,10 @@ PHP_FUNCTION(mb_strcut)
2806 2810 }
2807 2811 }
2808 2812
2809   - if (argc < 3) {
  2813 + if (argc < 3 || !zlen) {
2810 2814 len = string.len;
  2815 + } else {
  2816 + len = Z_LVAL_P(zlen);
2811 2817 }
2812 2818
2813 2819 /* if "from" position is negative, count start position from the end

0 comments on commit 0292a6f

Please sign in to comment.
Something went wrong with that request. Please try again.