Skip to content

Commit b59718b

Browse files
Fix bug #74725 (html_errors=1 breaks unhandled exceptions)
1 parent b06f8cb commit b59718b

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Fixed bug #74947 (Segfault in scanner on INF number). (Laruence)
77
. Fixed bug #74954 (null deref and segfault in zend_generator_resume()). (Bob)
8+
. Fixed bug #74725 (html_errors=1 breaks unhandled exceptions). (Andrea)
89

910
- cURL:
1011
. Fixed bug #74125 (Fixed finding CURL on systems with multiarch support).

main/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,10 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
722722
buffer_len = (int)vspprintf(&buffer, 0, format, args);
723723

724724
if (PG(html_errors)) {
725-
replace_buffer = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, NULL);
725+
replace_buffer = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, SG(default_charset));
726726
/* Retry with substituting invalid chars on fail. */
727727
if (!replace_buffer || ZSTR_LEN(replace_buffer) < 1) {
728-
replace_buffer = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT | ENT_HTML_SUBSTITUTE_ERRORS, NULL);
728+
replace_buffer = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT | ENT_HTML_SUBSTITUTE_ERRORS, SG(default_charset));
729729
}
730730

731731
efree(buffer);
@@ -792,7 +792,7 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
792792
}
793793

794794
if (PG(html_errors)) {
795-
replace_origin = php_escape_html_entities((unsigned char*)origin, origin_len, 0, ENT_COMPAT, NULL);
795+
replace_origin = php_escape_html_entities((unsigned char*)origin, origin_len, 0, ENT_COMPAT, SG(default_charset));
796796
efree(origin);
797797
origin = ZSTR_VAL(replace_origin);
798798
}
@@ -1106,7 +1106,7 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u
11061106

11071107
if (PG(html_errors)) {
11081108
if (type == E_ERROR || type == E_PARSE) {
1109-
zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, NULL);
1109+
zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, SG(default_charset));
11101110
php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), error_filename, error_lineno, STR_PRINT(append_string));
11111111
zend_string_free(buf);
11121112
} else {

tests/output/bug74725.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #74725: html_errors=1 breaks unhandled exceptions
3+
--FILE--
4+
<?php
5+
ini_set('display_errors', 1);
6+
ini_set('html_errors', 1);
7+
ini_set('default_charset', "Windows-1251");
8+
throw new Exception("\xF2\xE5\xF1\xF2");
9+
// Note to test reader: this file is in Windows-1251 (vim: `:e ++enc=cp1251`)
10+
?>
11+
--EXPECTF--
12+
<br />
13+
<b>Fatal error</b>: Uncaught Exception: òåñò in %s:5
14+
Stack trace:
15+
#0 {main}
16+
thrown in <b>%s</b> on line <b>5</b><br />

0 commit comments

Comments
 (0)