Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #1551: Object with 0-length property name is returned wrongly #446

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rebuild.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

bit64=`php -r 'echo PHP_INT_SIZE == 8 ? "1" : "0";'`
bit64=`php -n -r 'echo PHP_INT_SIZE == 8 ? "1" : "0";'`

if [[ ${bit64} != "1" ]]; then
export CFLAGS="-m32"
Expand Down
11 changes: 11 additions & 0 deletions tests/bug01551.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$object = (object) [
null => [ 1, 2, [ 3, 4, 5 ] ],
];

$array = [
null => [ 1, 2, [ 3, 4, 5 ] ],
];

count($array);
?>
67 changes: 67 additions & 0 deletions tests/bug01551.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--TEST--
Test for bug #1551: Can't debug properties with an empty name
--SKIPIF--
<?php if (getenv("SKIP_DBGP_TESTS")) { exit("skip Excluding DBGp tests"); } ?>
--FILE--
<?php
require 'dbgp/dbgpclient.php';
$data = file_get_contents(dirname(__FILE__) . '/bug01551.inc');

$commands = array(
'step_into',
'breakpoint_set -t line -n 10',
'run',
'property_get -n $object',
'property_get -n $object->{""}',
'property_get -n $object->{""}[2]',
'property_get -n $array',
'property_get -n $array[""]',
'property_get -n $array[""][2]',
'detach'
);

dbgpRun( $data, $commands );
?>
--EXPECT--
<?xml version="1.0" encoding="iso-8859-1"?>
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://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[https://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="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="1" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="3"></xdebug:message></response>

-> breakpoint_set -i 2 -t line -n 10
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id=""></response>

-> run -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="3" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="10"></xdebug:message></response>

-> property_get -i 4 -n $object
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="4"><property name="$object" fullname="$object" type="object" classname="stdClass" children="1" numchildren="1" page="0" pagesize="32"><property name="" fullname="$object-&gt;{&quot;&quot;}" facet="public" type="array" children="1" numchildren="3"></property></property></response>

-> property_get -i 5 -n $object->{""}
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="5"><property name="$object-&gt;{&quot;&quot;}" fullname="$object-&gt;{&quot;&quot;}" type="array" children="1" numchildren="3" page="0" pagesize="32"><property name="0" fullname="$object-&gt;{&quot;&quot;}[0]" type="int"><![CDATA[1]]></property><property name="1" fullname="$object-&gt;{&quot;&quot;}[1]" type="int"><![CDATA[2]]></property><property name="2" fullname="$object-&gt;{&quot;&quot;}[2]" type="array" children="1" numchildren="3"></property></property></response>

-> property_get -i 6 -n $object->{""}[2]
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="6"><property name="$object-&gt;{&quot;&quot;}[2]" fullname="$object-&gt;{&quot;&quot;}[2]" type="array" children="1" numchildren="3" page="0" pagesize="32"><property name="0" fullname="$object-&gt;{&quot;&quot;}[2][0]" type="int"><![CDATA[3]]></property><property name="1" fullname="$object-&gt;{&quot;&quot;}[2][1]" type="int"><![CDATA[4]]></property><property name="2" fullname="$object-&gt;{&quot;&quot;}[2][2]" type="int"><![CDATA[5]]></property></property></response>

-> property_get -i 7 -n $array
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="7"><property name="$array" fullname="$array" type="array" children="1" numchildren="1" page="0" pagesize="32"><property name="" fullname="$array[&quot;&quot;]" type="array" children="1" numchildren="3"></property></property></response>

-> property_get -i 8 -n $array[""]
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="8"><property name="$array[&quot;&quot;]" fullname="$array[&quot;&quot;]" type="array" children="1" numchildren="3" page="0" pagesize="32"><property name="0" fullname="$array[&quot;&quot;][0]" type="int"><![CDATA[1]]></property><property name="1" fullname="$array[&quot;&quot;][1]" type="int"><![CDATA[2]]></property><property name="2" fullname="$array[&quot;&quot;][2]" type="array" children="1" numchildren="3"></property></property></response>

-> property_get -i 9 -n $array[""][2]
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="9"><property name="$array[&quot;&quot;][2]" fullname="$array[&quot;&quot;][2]" type="array" children="1" numchildren="3" page="0" pagesize="32"><property name="0" fullname="$array[&quot;&quot;][2][0]" type="int"><![CDATA[3]]></property><property name="1" fullname="$array[&quot;&quot;][2][1]" type="int"><![CDATA[4]]></property><property name="2" fullname="$array[&quot;&quot;][2][2]" type="int"><![CDATA[5]]></property></property></response>

-> detach -i 10
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="detach" transaction_id="10" status="stopping" reason="ok"></response>
56 changes: 50 additions & 6 deletions xdebug_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,12 @@ void xdebug_get_php_symbol(zval *retval, xdebug_str* name)
break;
case 2:
if (ptr[ctr] != '>') {
keyword = &ptr[ctr];
state = 1;
if (ptr[ctr] == '{') {
state = 11;
} else {
keyword = &ptr[ctr];
state = 1;
}
}
break;
case 8:
Expand Down Expand Up @@ -726,6 +730,42 @@ void xdebug_get_php_symbol(zval *retval, xdebug_str* name)
}
}
break;

case 11:
if (ptr[ctr] == '\'' || ptr[ctr] == '"') {
state = 12;
keyword = &ptr[ctr] + 1;
quotechar = ptr[ctr];
}
break;

case 12: /* Inside {" */
if (ptr[ctr] == '\\') {
state = 13; /* Escaped character */
} else if (ptr[ctr] == quotechar) {
quotechar = 0;
state = 14;
keyword_end = &ptr[ctr];
fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce TSRMLS_CC);
if (current_classname) {
efree(current_classname);
}
current_classname = NULL;
cc_length = 0;
if (is_objectish(retval)) {
current_classname = fetch_classname_from_zval(retval, &cc_length, &current_ce TSRMLS_CC);
}
keyword = NULL;
}
break;
case 13: /* Escaped character */
state = 12;
break;
case 14:
if (ptr[ctr] == '}') {
state = 1;
}
break;
}
ctr++;
}
Expand Down Expand Up @@ -1757,7 +1797,7 @@ static int xdebug_array_element_export_xml_node(zval *zv_nptr, zend_ulong index_
return 0;
}

static int xdebug_object_element_export_xml_node(xdebug_object_item *item_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_xml_node *parent, xdebug_str *parent_name, xdebug_var_export_options *options, char *class_name)
static int xdebug_object_element_export_xml_node(xdebug_object_item *item_nptr, int level, xdebug_xml_node *parent, xdebug_str *parent_name, xdebug_var_export_options *options, char *class_name)
{
xdebug_object_item **item = &item_nptr;
xdebug_xml_node *node;
Expand All @@ -1771,7 +1811,7 @@ static int xdebug_object_element_export_xml_node(xdebug_object_item *item_nptr,
node = xdebug_xml_node_init("property");
options->force_extended = 0;

if ((*item)->name_len != 0) {
if ((*item)->name != NULL) {
char *prop_class_name;
xdebug_str *property_name;

Expand All @@ -1798,7 +1838,11 @@ static int xdebug_object_element_export_xml_node(xdebug_object_item *item_nptr,
xdebug_str_add_str(tmp_fullname, parent_name);
xdebug_str_add(tmp_fullname, (*item)->type == XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY ? "::" : "->", 0);
if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) {
xdebug_str_add_str(tmp_fullname, property_name);
if (property_name->l> 0) {
xdebug_str_add_str(tmp_fullname, property_name);
} else {
xdebug_str_addl(tmp_fullname, "{\"\"}", 4, 0);
}
} else {
xdebug_str_addc(tmp_fullname, '*');
xdebug_str_add(tmp_fullname, prop_class_name, 0);
Expand Down Expand Up @@ -2093,7 +2137,7 @@ void xdebug_var_export_xml_node(zval **struc, xdebug_str *name, xdebug_xml_node
xdebug_zend_hash_apply_protection_begin(merged_hash);

ZEND_HASH_FOREACH_KEY_PTR(merged_hash, num, key, xoi_val) {
xdebug_object_element_export_xml_node(xoi_val, num, key, level, node, name, options, class_name->d);
xdebug_object_element_export_xml_node(xoi_val, level, node, name, options, class_name->d);
} ZEND_HASH_FOREACH_END();

xdebug_zend_hash_apply_protection_end(merged_hash);
Expand Down