Skip to content

Commit 26c4b92

Browse files
committed
Merged pull request xdebug#1003
2 parents 6b7b964 + 29204be commit 26c4b92

File tree

3 files changed

+79
-26
lines changed

3 files changed

+79
-26
lines changed

src/lib/var.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static void fetch_zval_from_symbol_table(
462462
if (xdebug_lib_has_active_object()) {
463463
ZVAL_COPY(&tmp_retval, xdebug_lib_get_active_object());
464464
} else {
465-
ZVAL_NULL(&tmp_retval);
465+
ZVAL_UNDEF(&tmp_retval);
466466
}
467467
goto cleanup;
468468
}
@@ -495,40 +495,44 @@ static void fetch_zval_from_symbol_table(
495495
XDEBUG_BREAK_INTENTIONALLY_MISSING
496496

497497
case XF_ST_OBJ_PROPERTY:
498+
/* If we don't have an object, bail out */
499+
if (!value_in || Z_TYPE_P(value_in) != IS_OBJECT) {
500+
ZVAL_UNDEF(&tmp_retval);
501+
goto cleanup;
502+
}
503+
498504
/* Let's see if there is a debug handler */
499-
if (value_in && Z_TYPE_P(value_in) == IS_OBJECT) {
500-
myht = xdebug_objdebug_pp(&value_in, XDEBUG_VAR_OBJDEBUG_DEFAULT);
505+
myht = xdebug_objdebug_pp(&value_in, XDEBUG_VAR_OBJDEBUG_DEFAULT);
501506

502-
if (myht) {
503-
/* As a normal (public) property */
504-
zval *tmp = zend_symtable_str_find(myht, name, name_length);
505-
if (tmp != NULL) {
507+
if (myht) {
508+
/* As a normal (public) property */
509+
zval *tmp = zend_symtable_str_find(myht, name, name_length);
510+
if (tmp != NULL) {
506511
#if PHP_VERSION_ID >= 80400
507-
if (Z_TYPE_P(tmp) == IS_PTR) {
508-
zend_release_properties(myht);
509-
goto skip_for_property_hook;
510-
}
511-
#endif
512-
ZVAL_COPY(&tmp_retval, tmp);
512+
if (Z_TYPE_P(tmp) == IS_PTR) {
513513
zend_release_properties(myht);
514-
goto cleanup;
514+
goto skip_for_property_hook;
515515
}
516+
#endif
517+
ZVAL_COPY(&tmp_retval, tmp);
518+
zend_release_properties(myht);
519+
goto cleanup;
520+
}
516521

517-
/* As a private property */
518-
{
519-
char *unmangled = replace_star_by_null(name, name_length);
520-
zval *tmp = zend_symtable_str_find(myht, unmangled, name_length);
521-
if (tmp != NULL) {
522-
ZVAL_COPY(&tmp_retval, tmp);
523-
zend_release_properties(myht);
524-
xdfree(unmangled);
525-
goto cleanup;
526-
}
522+
/* As a private property */
523+
{
524+
char *unmangled = replace_star_by_null(name, name_length);
525+
zval *tmp = zend_symtable_str_find(myht, unmangled, name_length);
526+
if (tmp != NULL) {
527+
ZVAL_COPY(&tmp_retval, tmp);
528+
zend_release_properties(myht);
527529
xdfree(unmangled);
530+
goto cleanup;
528531
}
529-
530-
zend_release_properties(myht);
532+
xdfree(unmangled);
531533
}
534+
535+
zend_release_properties(myht);
532536
}
533537

534538
#if PHP_VERSION_ID >= 80400

tests/debugger/bug02331.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$GLOBALS['->h'] = 5;
3+
echo(1);
4+
?>

tests/debugger/bug02331.phpt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Test for bug #2331: Segmentation fault with 'invalid' variable names
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/../utils.inc';
6+
check_reqs('dbgp');
7+
?>
8+
--FILE--
9+
<?php
10+
require 'dbgp/dbgpclient.php';
11+
$filename = dirname(__FILE__) . '/bug02331.inc';
12+
13+
$commands = array(
14+
'step_into',
15+
'context_get -c 1',
16+
'step_into',
17+
'context_get -c 1',
18+
'detach',
19+
);
20+
21+
dbgpRunFile( $filename, $commands );
22+
?>
23+
--EXPECTF--
24+
<?xml version="1.0" encoding="iso-8859-1"?>
25+
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://bug02331.inc" language="PHP" xdebug:language_version="" protocol_version="1.0" appid=""><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>
26+
27+
-> step_into -i 1
28+
<?xml version="1.0" encoding="iso-8859-1"?>
29+
<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://bug02331.inc" lineno="2"></xdebug:message></response>
30+
31+
-> context_get -i 2 -c 1
32+
<?xml version="1.0" encoding="iso-8859-1"?>
33+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="2" context="1">%s</response>
34+
35+
-> step_into -i 3
36+
<?xml version="1.0" encoding="iso-8859-1"?>
37+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="3" status="break" reason="ok"><xdebug:message filename="file://bug02331.inc" lineno="3"></xdebug:message></response>
38+
39+
-> context_get -i 4 -c 1
40+
<?xml version="1.0" encoding="iso-8859-1"?>
41+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="4" context="1">%s</response>
42+
43+
-> detach -i 5
44+
<?xml version="1.0" encoding="iso-8859-1"?>
45+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="detach" transaction_id="5" status="stopping" reason="ok"></response>

0 commit comments

Comments
 (0)