Skip to content

Commit 1239ea7

Browse files
committed
Merge branch 'xdebug_3_5'
* xdebug_3_5: Fixed issue #2431: Crash when trying to retrieve Windows-style URL with not enough characters
2 parents 6ebd355 + edaa901 commit 1239ea7

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

src/debugger/handler_dbgp.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ static xdebug_str* return_file_source(zend_string *filename, int begin, int end)
518518
char *line = NULL;
519519
xdebug_str *source = xdebug_str_new();
520520
char *tmp_filename = NULL;
521+
#ifndef WIN32
522+
php_stream_statbuf ssb = {0};
523+
#endif
521524

522525
if (i < 0) {
523526
begin = 0;
@@ -531,11 +534,24 @@ static xdebug_str* return_file_source(zend_string *filename, int begin, int end)
531534
NULL);
532535
xdfree(tmp_filename);
533536

534-
/* Read until the "begin" line has been read */
537+
/* If we couldn't open the stream, bail out */
535538
if (!stream) {
536539
return NULL;
537540
}
538541

542+
#ifndef WIN32
543+
/* Check what we're dealing with */
544+
if (php_stream_stat(stream, &ssb) != 0) {
545+
php_stream_close(stream);
546+
return NULL;
547+
}
548+
/* If it's a directory, bail out */
549+
if (S_ISDIR(ssb.sb.st_mode)) {
550+
php_stream_close(stream);
551+
return NULL;
552+
}
553+
#endif
554+
539555
/* skip to the first requested line */
540556
while (i > 0 && !php_stream_eof(stream)) {
541557
if (line) {

src/lib/usefulstuff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ char *xdebug_path_from_url(zend_string *fileurl)
271271

272272
if (tmp) {
273273
fp = tmp + 7;
274-
if (fp[0] == '/' && fp[2] == ':') {
274+
if (fp[0] == '/' && fp[1] != '\0' && fp[2] == ':') {
275275
fp++;
276276
}
277277
ret = xdstrdup(fp);

tests/debugger/bug02431.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Test for bug #2431: Crash when trying to retrieve Windows-style URL with not enough characters
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__) . '/bug00622.inc';
12+
13+
$commands = array(
14+
'step_into',
15+
"source -f file:///",
16+
'step_into',
17+
'detach'
18+
);
19+
20+
dbgpRunFile( $filename, $commands );
21+
?>
22+
--EXPECTF--
23+
<?xml version="1.0" encoding="iso-8859-1"?>
24+
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://bug00622.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>
25+
26+
-> step_into -i 1
27+
<?xml version="1.0" encoding="iso-8859-1"?>
28+
<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://bug00622.inc" lineno="2"></xdebug:message></response>
29+
30+
-> source -i 2 -f file:///
31+
<?xml version="1.0" encoding="iso-8859-1"?>
32+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="source" transaction_id="2" status="break" reason="ok"><error code="100"><message><![CDATA[can not open file]]></message></error></response>
33+
34+
-> step_into -i 3
35+
<?xml version="1.0" encoding="iso-8859-1"?>
36+
<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://bug00622.inc" lineno="8"></xdebug:message></response>
37+
38+
-> detach -i 4
39+
<?xml version="1.0" encoding="iso-8859-1"?>
40+
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="detach" transaction_id="4" status="stopping" reason="ok"></response>

0 commit comments

Comments
 (0)