Skip to content

Commit

Permalink
Fixed bug xdebug#305: xdebug exception handler doesn't properly handl…
Browse files Browse the repository at this point in the history
…e special chars.
  • Loading branch information
derickr committed Oct 1, 2011
1 parent b0faa73 commit 9b91df3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
19 changes: 19 additions & 0 deletions tests/bug00305.phpt
@@ -0,0 +1,19 @@
--TEST--
Test for bug #305: xdebug exception handler doesn't properly handle special chars
--INI--
html_errors=1
xdebug.default_enable=1
xdebug.file_link_format=xdebug://%f@%l
--FILE--
<?php
throw new Exception("<MARK>");
?>
--EXPECTF--
<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught exception 'Exception' with message '&lt;MARK&gt;' in <a style='color: black' href='xdebug://%sbug00305.php@2'>%sbug00305.php</a> on line <i>2</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Exception: &lt;MARK&gt; in <a style='color: black' href='xdebug://%sbug00305.php@2'>%sbug00305.php</a> on line <i>2</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>{main}( )</td><td title='%sbug00305.php' bgcolor='#eeeeec'><a style='color: black' href='xdebug://%sbug00305.php@0'>../bug00305.php<b>:</b>0</a></td></tr>
</table></font>
15 changes: 13 additions & 2 deletions xdebug_stack.c
Expand Up @@ -24,6 +24,7 @@
#include "xdebug_str.h"
#include "xdebug_superglobals.h"
#include "xdebug_var.h"
#include "ext/standard/html.h"

#include "main/php_ini.h"

Expand Down Expand Up @@ -226,16 +227,26 @@ static void xdebug_append_error_head(xdebug_str *str, int html TSRMLS_DC)
void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC)
{
char **formats = html ? html_formats : text_formats;
char *escaped;
size_t newlen;

if (html) {
escaped = php_escape_html_entities_ex(buffer, strlen(buffer), &newlen, 0, 0, NULL, 1 TSRMLS_CC);
} else {
escaped = estrdup(buffer);
}

if (strlen(XG(file_link_format)) > 0 && html) {
char *file_link;

create_file_link(&file_link, error_filename, error_lineno TSRMLS_CC);
xdebug_str_add(str, xdebug_sprintf(formats[11], error_type_str, buffer, file_link, error_filename, error_lineno), 1);
xdebug_str_add(str, xdebug_sprintf(formats[11], error_type_str, escaped, file_link, error_filename, error_lineno), 1);
xdfree(file_link);
} else {
xdebug_str_add(str, xdebug_sprintf(formats[1], error_type_str, buffer, error_filename, error_lineno), 1);
xdebug_str_add(str, xdebug_sprintf(formats[1], error_type_str, escaped, error_filename, error_lineno), 1);
}

efree(escaped);
}

void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC)
Expand Down

0 comments on commit 9b91df3

Please sign in to comment.