Skip to content

Commit 9eda8c7

Browse files
committed
Merged pull request xdebug#1015
2 parents 02e76b4 + 078a852 commit 9eda8c7

File tree

66 files changed

+626
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+626
-466
lines changed

run-xdebug-tests.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
/* $Id: ff8fc1a09b14846e2a5daa9b51cc2b6e97f3ac3c $ */
2727

28+
require_once __DIR__ . '/tests/utils.inc';
29+
2830
/* Temporary variables while this file is being refactored. */
2931
/** @var ?JUnit */
3032
$junit = null;
@@ -2000,9 +2002,7 @@ function run_test(string $php, $file, array $env): string
20002002

20012003
if ($test->sectionNotEmpty('ENV')) {
20022004
$env_str = str_replace('{PWD}', dirname($file), $test->getSection('ENV'));
2003-
$env_str = str_replace('{RUNID}', getenv('UNIQ_RUN_ID'), $env_str);
2004-
$env_str = str_replace('{TEST_PHP_WORKER}', getenv('TEST_PHP_WORKER'), $env_str);
2005-
$env_str = str_replace('{TMP}', sys_get_temp_dir(), $env_str);
2005+
$env_str = preg_replace_callback('/{TMPFILE:(\S+)}/', function($matches) { return getTmpFile($matches[1]); }, $env_str);
20062006
foreach (explode("\n", $env_str) as $e) {
20072007
$e = explode('=', trim($e), 2);
20082008

@@ -2091,9 +2091,7 @@ function run_test(string $php, $file, array $env): string
20912091
// these may overwrite the test defaults...
20922092
if ($test->hasSection('INI')) {
20932093
$ini = str_replace('{PWD}', dirname($file), $test->getSection('INI'));
2094-
$ini = str_replace('{RUNID}', getenv('UNIQ_RUN_ID'), $ini);
2095-
$ini = str_replace('{TEST_PHP_WORKER}', getenv('TEST_PHP_WORKER'), $ini);
2096-
$ini = str_replace('{TMP}', sys_get_temp_dir(), $ini);
2094+
$ini = preg_replace_callback('/{TMPFILE:(\S+)}/', function($matches) { return getTmpFile($matches[1]); }, $ini);
20972095
$replacement = IS_WINDOWS ? '"' . PHP_BINARY . ' -r \"while ($in = fgets(STDIN)) echo $in;\" > $1"' : 'tee $1 >/dev/null';
20982096
$ini = preg_replace('/{MAIL:(\S+)}/', $replacement, $ini);
20992097
settings2array(preg_split("/[\n\r]+/", $ini), $ini_settings);

src/debugger/handler_dbgp.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,10 @@ DBGP_FUNC(eval)
11461146
/* base64 decode eval string */
11471147
eval_string = (char*) xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length);
11481148

1149+
if (!eval_string) {
1150+
RETURN_RESULT_WITH_MESSAGE(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_EVALUATING_CODE, xdebug_sprintf("%s: %s", error_message_from_code(XDEBUG_ERROR_EVALUATING_CODE), "invalid base64-encoded data value"));
1151+
}
1152+
11491153
res = xdebug_do_eval(eval_string, &ret_zval, &return_message);
11501154

11511155
xdfree(eval_string);
@@ -1273,9 +1277,25 @@ DBGP_FUNC(detach)
12731277
XG_DBG(stdout_mode) = 0;
12741278
XG_DBG(detached) = 1;
12751279

1276-
if (CMD_OPTION_SET('-')) {
1277-
XG_DBG(context).detached_message = xdstrdup(CMD_OPTION_CHAR('-'));
1278-
xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "DETACH", "Debug client detached: %s.", XG_DBG(context).detached_message);
1280+
if (CMD_OPTION_SET('-') && CMD_OPTION_LEN('-') > 0) {
1281+
unsigned char *new_value;
1282+
size_t new_length = 0;
1283+
1284+
/* It should be base64 */
1285+
new_value = xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length);
1286+
1287+
/* But if not, we fall back if all characters are also printable. */
1288+
if (new_value) {
1289+
if (xdebug_is_printable((char*) new_value, new_length)) {
1290+
XG_DBG(context).detached_message = (char*) new_value;
1291+
} else {
1292+
xdfree(new_value);
1293+
XG_DBG(context).detached_message = xdstrdup(CMD_OPTION_CHAR('-'));
1294+
}
1295+
} else {
1296+
XG_DBG(context).detached_message = xdstrdup(CMD_OPTION_CHAR('-'));
1297+
}
1298+
xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "DETACH", "Debug client detached: %s", XG_DBG(context).detached_message);
12791299
}
12801300
}
12811301

@@ -1724,6 +1744,10 @@ DBGP_FUNC(property_set)
17241744

17251745
new_value = xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length);
17261746

1747+
if (!new_value) {
1748+
RETURN_RESULT_WITH_MESSAGE(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_EVALUATING_CODE, xdebug_sprintf("%s: %s", error_message_from_code(XDEBUG_ERROR_EVALUATING_CODE), "invalid base64-encoded data value"));
1749+
}
1750+
17271751
/* Set a cast, if requested through the 't' option */
17281752
cast_as = "";
17291753

src/lib/compat.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+----------------------------------------------------------------------+
33
| Xdebug |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 2002-2022 Derick Rethans <[email protected]> |
5+
| Copyright (c) 2002-2025 Derick Rethans <[email protected]> |
66
| (c) 1997-2004 Jim Winstead <[email protected]> |
77
| (c) 1998-2004 Andi Gutmans <[email protected]> and |
88
| Zeev Suraski <[email protected]> |
@@ -127,7 +127,7 @@ static unsigned char *xdebug_base64_encode_impl(const unsigned char *in, size_t
127127
}
128128
/* }}} */
129129

130-
static int xdebug_base64_decode_impl(const unsigned char *in, size_t inl, unsigned char *out, size_t *outl, zend_bool strict) /* {{{ */
130+
static bool xdebug_base64_decode_impl(const unsigned char *in, size_t inl, unsigned char *out, size_t *outl, zend_bool strict) /* {{{ */
131131
{
132132
int ch;
133133
size_t i = 0, padding = 0, j = *outl;
@@ -190,10 +190,10 @@ static int xdebug_base64_decode_impl(const unsigned char *in, size_t inl, unsign
190190
*outl = j;
191191
out[j] = '\0';
192192

193-
return 1;
193+
return true;
194194

195195
fail:
196-
return 0;
196+
return false;
197197
}
198198
/* }}} */
199199

@@ -210,9 +210,15 @@ unsigned char *xdebug_base64_encode(unsigned char *data, size_t data_len, size_t
210210

211211
unsigned char *xdebug_base64_decode(unsigned char *data, size_t data_len, size_t *new_len)
212212
{
213+
bool ok;
213214
unsigned char *retval = xdmalloc(data_len + 1);
214215

215-
xdebug_base64_decode_impl(data, data_len, retval, new_len, 0);
216+
ok = xdebug_base64_decode_impl(data, data_len, retval, new_len, true);
217+
218+
if (!ok) {
219+
xdfree(retval);
220+
return NULL;
221+
}
216222

217223
return retval;
218224
}

src/lib/usefulstuff.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+----------------------------------------------------------------------+
33
| Xdebug |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 2002-2022 Derick Rethans |
5+
| Copyright (c) 2002-2025 Derick Rethans |
66
+----------------------------------------------------------------------+
77
| This source file is subject to version 1.01 of the Xdebug license, |
88
| that is bundled with this package in the file LICENSE, and is |
@@ -137,6 +137,19 @@ void xdebug_explode(const char *delim, const char *str, xdebug_arg *args, int li
137137
}
138138
}
139139

140+
bool xdebug_is_printable(const char *str, size_t len)
141+
{
142+
size_t i;
143+
144+
for (i = 0; i < len; i++) {
145+
if (!isprint(str[i])) {
146+
return false;
147+
}
148+
}
149+
150+
return true;
151+
}
152+
140153
const char* xdebug_memnstr(const char *haystack, const char *needle, int needle_len, const char *end)
141154
{
142155
const char *p = haystack;

src/lib/usefulstuff.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+----------------------------------------------------------------------+
33
| Xdebug |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 2002-2021 Derick Rethans |
5+
| Copyright (c) 2002-2025 Derick Rethans |
66
+----------------------------------------------------------------------+
77
| This source file is subject to version 1.01 of the Xdebug license, |
88
| that is bundled with this package in the file LICENSE, and is |
@@ -30,6 +30,7 @@ void xdebug_arg_dtor(xdebug_arg *arg);
3030

3131
xdebug_str* xdebug_join(const char *delim, xdebug_arg *args, int begin, int end);
3232
void xdebug_explode(const char *delim, const char *str, xdebug_arg *args, int limit);
33+
bool xdebug_is_printable(const char *str, size_t len);
3334
const char* xdebug_memnstr(const char *haystack, const char *needle, int needle_len, const char *end);
3435
char* xdebug_strrstr(const char* haystack, const char* needle);
3536
char *xdebug_trim(const char *str);

tests/base/bug00801.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test for bug #801: Segfault with streamwrapper, unclosed $fp and xdebug on destruction
33
--FILE--
44
<?php
5+
require_once __DIR__ . '/../utils.inc';
56

67
class Handler
78
{
@@ -25,7 +26,7 @@ class Wrapper
2526

2627
public function stream_open($path, $mode)
2728
{
28-
$this->_fp = fopen(sys_get_temp_dir() . '/' . getenv('UNIQ_RUN_ID') . getenv('TEST_PHP_WORKER') . 'asdf', $mode);
29+
$this->_fp = fopen(getTmpFile('asdf'), $mode);
2930

3031
return true;
3132
}
@@ -43,7 +44,9 @@ Manager::$stuff->Logs = new Handler;
4344
?>
4445
--AFTER--
4546
<?php
46-
unlink(sys_get_temp_dir() .'/' . getenv('UNIQ_RUN_ID') . getenv('TEST_PHP_WORKER') . 'asdf');
47+
require_once __DIR__ . '/../utils.inc';
48+
49+
unlink(getTmpFile('asdf'));
4750
?>
4851
--EXPECT--
4952
DONE

tests/coverage/dump-branch-coverage.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require_once __DIR__ . '/../utils.inc';
44

55
function dump_branch_coverage($info)
66
{
7-
file_put_contents( getTmpDir() . "xdebug-paths.dot", branch_coverage_to_dot( $info ) );
7+
file_put_contents( getTmpFile( "xdebug-paths.dot" ), branch_coverage_to_dot( $info ) );
88
ksort($info);
99

1010
foreach ( $info as $fname => $file )

tests/debugger/bug00964-001.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ HTTP_X_FORWARDED_FOR=192.168.111.111
1010
--INI--
1111
xdebug.mode=debug
1212
xdebug.start_with_request=yes
13-
xdebug.log={TMP}/bug964.txt
13+
xdebug.log={TMPFILE:bug964.txt}
1414
xdebug.discover_client_host=1
1515
xdebug.client_port=9903
1616
--FILE--
1717
<?php
18+
require_once __DIR__ . '/../utils.inc';
19+
1820
preg_match(
1921
"#Client host discovered through HTTP header, connecting to ([^:]+):9903#",
20-
file_get_contents( sys_get_temp_dir() . "/bug964.txt" ),
22+
file_get_contents(getTmpFile('bug964.txt')),
2123
$match
2224
);
23-
unlink( sys_get_temp_dir() . "/bug964.txt" );
25+
unlink(getTmpFile('bug964.txt'));
2426
echo $match[1];
2527
?>
2628
--EXPECTF--

tests/debugger/bug00964-002.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ HTTP_X_FORWARDED_FOR=192.168.111.111, 10.1.2.3, 10.1.2.4
1010
--INI--
1111
xdebug.mode=debug
1212
xdebug.start_with_request=yes
13-
xdebug.log={TMP}/bug964.txt
13+
xdebug.log={TMPFILE:bug964.txt}
1414
xdebug.discover_client_host=1
1515
xdebug.client_port=9903
1616
--FILE--
1717
<?php
18+
require_once __DIR__ . '/../utils.inc';
19+
1820
preg_match(
1921
"#Client host discovered through HTTP header, connecting to ([^:]+):9903#",
20-
file_get_contents( sys_get_temp_dir() . "/bug964.txt" ),
22+
file_get_contents(getTmpFile("bug964.txt")),
2123
$match
2224
);
23-
unlink( sys_get_temp_dir() . "/bug964.txt" );
25+
unlink(getTmpFile("bug964.txt"));
2426
echo $match[1];
2527
?>
2628
--EXPECTF--

tests/debugger/bug01978.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $commands = array(
2020
'detach',
2121
);
2222

23-
$xdebugLogFileName = sys_get_temp_dir() . '/' . getenv('UNIQ_RUN_ID') . getenv('TEST_PHP_WORKER') . 'remote-log-1978.txt';
23+
$xdebugLogFileName = getTmpFile('remote-log-1978.txt');
2424
@unlink( $xdebugLogFileName );
2525

2626
dbgpRunFile( $filename, $commands, [ 'xdebug.log' => $xdebugLogFileName, 'xdebug.log_level' => 7, 'xdebug.control_socket' => 'off' ] );

0 commit comments

Comments
 (0)