Skip to content

Commit c09e6c5

Browse files
committed
Fix GH-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.
1 parent 5942a61 commit c09e6c5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/mbstring/mbstring.c

Lines changed: 3 additions & 1 deletion
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

Lines changed: 16 additions & 0 deletions
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)