Skip to content

Commit c7d3dc6

Browse files
committed
Fix phpGH-17989: mb_output_handler crash with unset http_output_conv_mimetypes
The INI option can be NULL or invalid, resulting in a NULL global. So we have to add a NULL check. Closes phpGH-17996.
1 parent d6ee360 commit c7d3dc6

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug GH-17984 (calls with arguments as array with references).
77
(David Carlier)
88

9+
- Mbstring:
10+
. Fixed bug GH-17989 (mb_output_handler crash with unset
11+
http_output_conv_mimetypes). (nielsdos)
12+
913
- Treewide:
1014
. Fixed bug GH-17736 (Assertion failure zend_reference_destroy()). (nielsdos)
1115

ext/mbstring/mbstring.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,9 @@ PHP_FUNCTION(mb_output_handler)
15671567
char *mimetype = NULL;
15681568

15691569
/* Analyze mime type */
1570-
if (SG(sapi_headers).mimetype && _php_mb_match_regex(MBSTRG(http_output_conv_mimetypes), SG(sapi_headers).mimetype, strlen(SG(sapi_headers).mimetype))) {
1570+
if (SG(sapi_headers).mimetype
1571+
&& MBSTRG(http_output_conv_mimetypes)
1572+
&& _php_mb_match_regex(MBSTRG(http_output_conv_mimetypes), SG(sapi_headers).mimetype, strlen(SG(sapi_headers).mimetype))) {
15711573
char *s;
15721574
if ((s = strchr(SG(sapi_headers).mimetype, ';')) == NULL) {
15731575
mimetype = estrdup(SG(sapi_headers).mimetype);

ext/mbstring/tests/gh17989.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-17989 (mb_output_handler crash with unset http_output_conv_mimetypes)
3+
--EXTENSIONS--
4+
mbstring
5+
--INI--
6+
mbstring.http_output_conv_mimetypes=
7+
--FILE--
8+
<?php
9+
echo "set mime type via this echo\n";
10+
ob_start('mb_output_handler');
11+
echo "hi";
12+
ob_flush();
13+
?>
14+
--EXPECT--
15+
set mime type via this echo
16+
hi

0 commit comments

Comments
 (0)