Permalink
Browse files

Merged pull request #402

  • Loading branch information...
derickr committed Jan 14, 2018
2 parents 9655deb + 8ee6d88 commit 891f0245421cf448abb1bc826ca09e982b49f44c
File renamed without changes.
View
@@ -0,0 +1,51 @@
--TEST--
Test for bug #421: xdebug sends back invalid characters in xml sometimes
--SKIPIF--
<?php
if (getenv("SKIP_DBGP_TESTS")) { exit("skip Excluding DBGp tests"); }
if (in_array('SimpleXMLIterator', get_declared_classes()) == false) { echo "skip SimpleXML extension required\n"; }
?>
--FILE--
<?php
require 'dbgp/dbgpclient.php';
$data = file_get_contents( dirname(__FILE__) . '/bug00421.inc' );
$commands = array(
'step_into',
'feature_set -n max_depth -v 0',
'breakpoint_set -t line -n 25',
'run',
'context_get -c 0',
'detach'
);
dbgpRun( $data, $commands );
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///%sxdebug-dbgp-test.php" language="PHP" xdebug:language_version="" protocol_version="1.0" appid="" idekey=""><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2%d by Derick Rethans]]></copyright></init>
-> step_into -i 1
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="1" status="break" reason="ok"><xdebug:message filename="file:///%sxdebug-dbgp-test.php" lineno="2"></xdebug:message></response>
-> feature_set -i 2 -n max_depth -v 0
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>
-> breakpoint_set -i 3 -t line -n 25
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id=""></response>
-> run -i 4
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="4" status="break" reason="ok"><xdebug:message filename="file:///%sxdebug-dbgp-test.php" lineno="25"></xdebug:message></response>
-> context_get -i 5 -c 0
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="5" context="0"><property name="$currentPageXML" fullname="$currentPageXML" type="object" classname="SimpleXMLIterator" children="1" numchildren="2"></property><property name="$iterator" fullname="$iterator" type="object" classname="SimpleXMLIterator" children="1" numchildren="1"></property><property name="$name" fullname="$name" type="uninitialized"></property><property name="$pageXML" fullname="$pageXML" type="object" classname="SimpleXMLIterator" children="1" numchildren="2"></property><property name="$projectsIterator" fullname="$projectsIterator" type="array" children="1" numchildren="3"></property><property name="$siteXMLString" fullname="$siteXMLString" type="string" size="161" encoding="base64"><![CDATA[PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHNpdGU+CiAgICA8cGFnZSBuYW1lPSJwcm9qZWN0cyI+CiAgICAgICAgPHBhZ2UgbmFtZT0iUHJvamVjdCAxIiAvPgogICAgICAgIDxwYWdlIG5hbWU9IlByb2plY3QgMiIgLz4KICAgIDwvcGFnZT4KPC9zaXRlPgo=]]></property></response>
-> detach -i 6
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="detach" transaction_id="6" status="stopping" reason="ok"></response>
View
@@ -32,11 +32,11 @@ dbgpRun( $data, $commands );
-> context_get -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="3" context="0"><property name="$a" fullname="$a" type="object" classname="class@anonymous" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="3" context="0"><property name="$a" fullname="$a" type="object" classname="class@anonymous&#0;/tmp/xdebug-dbgp-test.php0x%s" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
-> property_get -i 4 -n $a
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="4"><property name="$a" fullname="$a" type="object" classname="class@anonymous" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="4"><property name="$a" fullname="$a" type="object" classname="class@anonymous&#0;/tmp/xdebug-dbgp-test.php0x%s" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
-> property_get -i 5 -n $a->a
<?xml version="1.0" encoding="iso-8859-1"?>
View
@@ -32,11 +32,11 @@ dbgpRun( $data, $commands );
-> context_get -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="3" context="0"><property name="$a" fullname="$a" type="object" classname="class@anonymous" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="3" context="0"><property name="$a" fullname="$a" type="object" classname="class@anonymous&#0;/tmp/xdebug-dbgp-test.php0x%s" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
-> property_get -i 4 -n $a
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="4"><property name="$a" fullname="$a" type="object" classname="class@anonymous" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="4"><property name="$a" fullname="$a" type="object" classname="class@anonymous&#0;/tmp/xdebug-dbgp-test.php0x%s" children="1" numchildren="1" page="0" pagesize="32"><property name="a" fullname="$a-&gt;a" facet="public" type="int"><![CDATA[42]]></property></property></response>
-> property_get -i 5 -n $a::a
<?xml version="1.0" encoding="iso-8859-1"?>
View
@@ -0,0 +1,6 @@
<?php
$name = "with_\0_null_char";
$$name = 42;
die();
?>
View
@@ -0,0 +1,47 @@
--TEST--
Test for bug #1514: (Root) Variable names with a NULL char are cut off at NULL char
--SKIPIF--
<?php if (getenv("SKIP_DBGP_TESTS")) { exit("skip Excluding DBGp tests"); } ?>
--FILE--
<?php
require 'dbgp/dbgpclient.php';
$data = file_get_contents(dirname(__FILE__) . '/bug01514.inc');
$commands = array(
'step_into',
'step_into',
'step_into',
'context_get',
'property_get -d 0 -c 0 -n $with_\0_null_char',
'property_get -d 0 -c 0 -n "$with_\\\0_null_char"',
);
dbgpRun( $data, $commands );
?>
--EXPECTF--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///tmp/xdebug-dbgp-test.php" language="PHP" xdebug:language_version="" protocol_version="1.0" appid="" idekey=""><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2099 by Derick Rethans]]></copyright></init>
-> step_into -i 1
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="1" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="2"></xdebug:message></response>
-> step_into -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="3"></xdebug:message></response>
-> step_into -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="3" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="5"></xdebug:message></response>
-> context_get -i 4
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="4" context="0"><property name="$name" fullname="$name" type="string" size="16" encoding="base64"><![CDATA[d2l0aF8AX251bGxfY2hhcg==]]></property><property name="$with_&#0;_null_char" fullname="$with_&#0;_null_char" type="uninitialized"></property></response>
-> property_get -i 5 -d 0 -c 0 -n $with_\0_null_char
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="5"><property name="$with_\0_null_char" fullname="$with_\0_null_char" type="int"><![CDATA[42]]></property></response>
-> property_get -i 6 -d 0 -c 0 -n "$with_\\0_null_char"
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="6"><property name="$with_\0_null_char" fullname="$with_\0_null_char" type="int"><![CDATA[42]]></property></response>
View
@@ -109,9 +109,8 @@ char* xdebug_fd_read_line_delim(int socketfd, fd_buf *context, int type, unsigne
char *xdebug_join(const char *delim, xdebug_arg *args, int begin, int end)
{
int i;
xdebug_str *ret;
xdebug_str *ret = xdebug_str_new();
xdebug_str_ptr_init(ret);
if (begin < 0) {
begin = 0;
}
View
@@ -1051,13 +1051,11 @@ static void xdebug_llist_string_dtor(void *dummy, void *elem)
}
}
static void xdebug_used_var_dtor(void *dummy, void *elem)
static void xdebug_declared_var_dtor(void *dummy, void *elem)
{
char *s = elem;
xdebug_str *s = (xdebug_str*) elem;
if (s) {
xdfree(s);
}
xdebug_str_free(s);
}
static void xdebug_stack_element_dtor(void *dummy, void *elem)
@@ -1091,9 +1089,9 @@ static void xdebug_stack_element_dtor(void *dummy, void *elem)
xdfree(e->include_filename);
}
if (e->used_vars) {
xdebug_llist_destroy(e->used_vars, NULL);
e->used_vars = NULL;
if (e->declared_vars) {
xdebug_llist_destroy(e->declared_vars, NULL);
e->declared_vars = NULL;
}
if (e->profile.call_list) {
@@ -1489,20 +1487,20 @@ static void add_used_variables(function_stack_entry *fse, zend_op_array *op_arra
{
unsigned int i = 0;
if (!fse->used_vars) {
fse->used_vars = xdebug_llist_alloc(xdebug_used_var_dtor);
if (!fse->declared_vars) {
fse->declared_vars = xdebug_llist_alloc(xdebug_declared_var_dtor);
}
/* Check parameters */
for (i = 0; i < fse->varc; i++) {
if (fse->var[i].name) {
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(fse->var[i].name));
xdebug_llist_insert_next(fse->declared_vars, XDEBUG_LLIST_TAIL(fse->declared_vars), xdebug_str_create(fse->var[i].name, fse->var[i].length));
}
}
/* gather used variables from compiled vars information */
while (i < (unsigned int) op_array->last_var) {
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(STR_NAME_VAL(op_array->vars[i])));
xdebug_llist_insert_next(fse->declared_vars, XDEBUG_LLIST_TAIL(fse->declared_vars), xdebug_str_create(STR_NAME_VAL(op_array->vars[i]), STR_NAME_LEN(op_array->vars[i])));
i++;
}
@@ -1513,11 +1511,11 @@ static void add_used_variables(function_stack_entry *fse, zend_op_array *op_arra
if (op_array->opcodes[i].op1_type == IS_CV) {
cv = (char *) xdebug_get_compiled_variable_name(op_array, op_array->opcodes[i].op1.var, &cv_len);
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(cv));
xdebug_llist_insert_next(fse->declared_vars, XDEBUG_LLIST_TAIL(fse->declared_vars), xdebug_str_create(cv, cv_len));
}
if (op_array->opcodes[i].op2_type == IS_CV) {
cv = (char *) xdebug_get_compiled_variable_name(op_array, op_array->opcodes[i].op2.var, &cv_len);
xdebug_llist_insert_next(fse->used_vars, XDEBUG_LLIST_TAIL(fse->used_vars), xdstrdup(cv));
xdebug_llist_insert_next(fse->declared_vars, XDEBUG_LLIST_TAIL(fse->declared_vars), xdebug_str_create(cv, cv_len));
}
i++;
}
View
@@ -240,9 +240,7 @@ static xdebug_dbgp_cmd* lookup_cmd(char *cmd)
static xdebug_str *make_message(xdebug_con *context, xdebug_xml_node *message TSRMLS_DC)
{
xdebug_str xml_message = XDEBUG_STR_INITIALIZER;
xdebug_str *ret;
xdebug_str_ptr_init(ret);
xdebug_str *ret = xdebug_str_new();
xdebug_xml_return_node(message, &xml_message);
if (XG(remote_log_file)) {
@@ -255,7 +253,7 @@ static xdebug_str *make_message(xdebug_con *context, xdebug_xml_node *message TS
xdebug_str_add(ret, "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n", 0);
xdebug_str_add(ret, xml_message.d, 0);
xdebug_str_addl(ret, "\0", 1, 0);
xdebug_str_dtor(xml_message);
xdebug_str_destroy(&xml_message);
return ret;
}
@@ -270,7 +268,7 @@ static void send_message(xdebug_con *context, xdebug_xml_node *message TSRMLS_DC
fprintf(stderr, "There was a problem sending %ld bytes on socket %d: %s", tmp->l, context->socket, sock_error);
efree(sock_error);
}
xdebug_str_ptr_dtor(tmp);
xdebug_str_free(tmp);
}
static xdebug_xml_node* get_symbol(char* name, xdebug_var_export_options *options TSRMLS_DC)
@@ -1624,14 +1622,14 @@ DBGP_FUNC(property_value)
options->max_data = old_max_data;
}
static void attach_used_var_with_contents(void *xml, xdebug_hash_element* he, void *options)
static void attach_declared_var_with_contents(void *xml, xdebug_hash_element* he, void *options)
{
char *name = (char*) he->ptr;
xdebug_str *name = (xdebug_str*) he->ptr;
xdebug_xml_node *node = (xdebug_xml_node *) xml;
xdebug_xml_node *contents;
TSRMLS_FETCH();
contents = get_symbol(name, options TSRMLS_CC);
contents = get_symbol(name->d, options TSRMLS_CC);
if (contents) {
xdebug_xml_add_child(node, contents);
} else {
@@ -1678,7 +1676,7 @@ static int xdebug_add_filtered_symboltable_var(zval *symbol TSRMLS_DC, int num_a
}
if (strcmp("GLOBALS", HASH_KEY_VAL(hash_key)) == 0) { return 0; }
xdebug_hash_add(tmp_hash, (char*) HASH_KEY_VAL(hash_key), strlen(HASH_KEY_VAL(hash_key)), HASH_KEY_VAL(hash_key));
xdebug_hash_add(tmp_hash, (char*) HASH_KEY_VAL(hash_key), HASH_KEY_LEN(hash_key), xdebug_str_create(HASH_KEY_VAL(hash_key), HASH_KEY_LEN(hash_key)));
return 0;
}
@@ -1744,11 +1742,11 @@ static int attach_context_vars(xdebug_xml_node *node, xdebug_var_export_options
XG(This) = fse->This;
/* Only show vars when they are scanned */
if (fse->used_vars) {
if (fse->declared_vars) {
xdebug_hash *tmp_hash;
/* Get a hash from all the used vars (which can have duplicates) */
tmp_hash = xdebug_used_var_hash_from_llist(fse->used_vars);
tmp_hash = xdebug_declared_var_hash_from_llist(fse->declared_vars);
/* Check for dynamically defined variables, but make sure we don't already
* have them. Also blacklist superglobals and argv/argc */
@@ -1858,7 +1856,7 @@ DBGP_FUNC(context_get)
/* Always reset to page = 0, as it might have been modified by property_get or property_value */
options->runtime[0].page = 0;
res = attach_context_vars(*retval, options, context_id, depth, attach_used_var_with_contents TSRMLS_CC);
res = attach_context_vars(*retval, options, context_id, depth, attach_declared_var_with_contents TSRMLS_CC);
switch (res) {
case 1:
RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID);
@@ -2255,11 +2253,11 @@ int xdebug_dbgp_init(xdebug_con *context, int mode)
options->runtime[i].current_element_nr = 0;
}
context->breakpoint_list = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_admin_dtor);
context->function_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_brk_dtor);
context->exception_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_brk_dtor);
context->breakpoint_list = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_admin_dtor);
context->function_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor);
context->exception_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor);
context->line_breakpoints = xdebug_llist_alloc((xdebug_llist_dtor) xdebug_llist_brk_dtor);
context->eval_id_lookup = xdebug_hash_alloc(64, (xdebug_hash_dtor) xdebug_hash_eval_info_dtor);
context->eval_id_lookup = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_eval_info_dtor);
context->eval_id_sequence = 0;
context->send_notifications = 0;
context->inhibit_notifications = 0;
Oops, something went wrong.

0 comments on commit 891f024

Please sign in to comment.