Skip to content

Commit 3ad0ebd

Browse files
committed
Fixed bug #77454
1 parent 8f66ca8 commit 3ad0ebd

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Fixed bug #77272 (imagescale() may return image resource on failure). (cmb)
1212
. Fixed bug #77391 (1bpp BMPs may fail to be loaded). (Romain Déoux, cmb)
1313

14+
- Mbstring:
15+
. Fixed bug #77454 (mb_scrub() silently truncates after a null byte).
16+
(64796c6e69 at gmail dot com)
17+
1418
- MySQLnd:
1519
. Fixed bug #75684 (In mysqlnd_ext_plugin.h the plugin methods family has
1620
no external visibility). (Anatol)

ext/mbstring/mbstring.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5260,11 +5260,9 @@ PHP_FUNCTION(mb_chr)
52605260
/* }}} */
52615261

52625262

5263-
static inline char* php_mb_scrub(const char* str, size_t str_len, const char* enc)
5263+
static inline char* php_mb_scrub(const char* str, size_t str_len, const char* enc, size_t *ret_len)
52645264
{
5265-
size_t ret_len;
5266-
5267-
return php_mb_convert_encoding(str, str_len, enc, enc, &ret_len);
5265+
return php_mb_convert_encoding(str, str_len, enc, enc, ret_len);
52685266
}
52695267

52705268

@@ -5276,6 +5274,7 @@ PHP_FUNCTION(mb_scrub)
52765274
char *enc = NULL;
52775275
size_t enc_len;
52785276
char *ret;
5277+
size_t ret_len;
52795278

52805279
ZEND_PARSE_PARAMETERS_START(1, 2)
52815280
Z_PARAM_STRING(str, str_len)
@@ -5290,13 +5289,13 @@ PHP_FUNCTION(mb_scrub)
52905289
RETURN_FALSE;
52915290
}
52925291

5293-
ret = php_mb_scrub(str, str_len, enc);
5292+
ret = php_mb_scrub(str, str_len, enc, &ret_len);
52945293

52955294
if (ret == NULL) {
52965295
RETURN_FALSE;
52975296
}
52985297

5299-
RETVAL_STRING(ret);
5298+
RETVAL_STRINGL(ret, ret_len);
53005299
efree(ret);
53015300
}
53025301
/* }}} */

ext/mbstring/tests/bug77454.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #77454: mb_scrub() silently truncates after a null byte
3+
--FILE--
4+
<?php
5+
$str = "before\0after";
6+
function test($str, $enc) {
7+
echo str_replace("\0", '\0', mb_scrub($str, $enc)), "\n";
8+
}
9+
test($str, 'latin1');
10+
test($str, 'utf-8');
11+
test($str, 'ascii');
12+
?>
13+
--EXPECT--
14+
before\0after
15+
before\0after
16+
before\0after

0 commit comments

Comments
 (0)