Skip to content

Commit

Permalink
Fix bug #74725 (html_errors=1 breaks unhandled exceptions)
Browse files Browse the repository at this point in the history
  • Loading branch information
hikari-no-yume committed Aug 12, 2017
1 parent b06f8cb commit b59718b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PHP NEWS
- Core:
. Fixed bug #74947 (Segfault in scanner on INF number). (Laruence)
. Fixed bug #74954 (null deref and segfault in zend_generator_resume()). (Bob)
. Fixed bug #74725 (html_errors=1 breaks unhandled exceptions). (Andrea)

- cURL:
. Fixed bug #74125 (Fixed finding CURL on systems with multiarch support).
Expand Down
8 changes: 4 additions & 4 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
buffer_len = (int)vspprintf(&buffer, 0, format, args);

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

efree(buffer);
Expand Down Expand Up @@ -792,7 +792,7 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
}

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

if (PG(html_errors)) {
if (type == E_ERROR || type == E_PARSE) {
zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, NULL);
zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, SG(default_charset));
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));
zend_string_free(buf);
} else {
Expand Down
16 changes: 16 additions & 0 deletions tests/output/bug74725.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Bug #74725: html_errors=1 breaks unhandled exceptions
--FILE--
<?php
ini_set('display_errors', 1);
ini_set('html_errors', 1);
ini_set('default_charset', "Windows-1251");
throw new Exception("\xF2\xE5\xF1\xF2");
// Note to test reader: this file is in Windows-1251 (vim: `:e ++enc=cp1251`)
?>
--EXPECTF--
<br />
<b>Fatal error</b>: Uncaught Exception: òåñò in %s:5
Stack trace:
#0 {main}
thrown in <b>%s</b> on line <b>5</b><br />

0 comments on commit b59718b

Please sign in to comment.