Skip to content

Commit fcf78df

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
2 parents a6b8651 + 742783c commit fcf78df

File tree

4 files changed

+66
-19
lines changed

4 files changed

+66
-19
lines changed

NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ PHP NEWS
33
?? ??? 2018, PHP 7.2.11
44

55
- POSIX:
6-
Fixed bug #75696 (posix_getgrnam fails to print details of group). (cmb)
6+
. Fixed bug #75696 (posix_getgrnam fails to print details of group). (cmb)
7+
8+
- Standard:
9+
. Fixed bug #73457 (Wrong error message when fopen FTP wrapped fails to open
10+
data connection). (Ville Hukkamäki)
711

812
13 Sep 2018, PHP 7.2.10
913

ext/ftp/tests/server.inc

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ if ($pid) {
356356
fputs($s, "550 No file named \"{$matches [1]}\"\r\n");
357357
break;
358358
}
359-
}elseif (preg_match('/^RETR ([\w\h]+)/', $buf, $matches)) {
359+
}elseif (preg_match('/^RETR ([\/]*[\w\h]+)/', $buf, $matches)) {
360360
if(!empty($pasv)){
361361
;
362362
}
@@ -412,6 +412,10 @@ if ($pid) {
412412
fputs($fs, "This is line $i of the test data.\n");
413413
}
414414
fputs($s, "226 Closing data Connection.\r\n");
415+
break;
416+
case "/bug73457":
417+
fputs($s, "150 File status okay; about to open data connection.\r\n");
418+
break;
415419

416420
default:
417421
fputs($s, "550 {$matches[1]}: No such file or directory \r\n");
@@ -426,29 +430,35 @@ if ($pid) {
426430
$host = "127.0.0.1";
427431
$i=0;
428432

429-
do {
430-
if (!empty($ssl)) {
431-
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
432-
} else {
433-
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port");
434-
}
435-
/* Could bind port, Try another port */
433+
if (empty($bug73457)) {
434+
do {
435+
if (!empty($ssl)) {
436+
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
437+
} else {
438+
$soc = @stream_socket_server("tcp://127.0.0.1:$pasv_port");
439+
}
440+
/* Could bind port, Try another port */
441+
if (!$soc) {
442+
$pasv_port = rand(50000, 65535);
443+
}
444+
$i++;
445+
} while ($i<10 && !$soc);
446+
436447
if (!$soc) {
437-
$pasv_port = rand(50000, 65535);
448+
echo "$errstr ($errno)\n";
449+
die("could not bind passive port\n");
438450
}
439-
$i++;
440-
} while ($i<10 && !$soc);
441-
442-
if (!$soc) {
443-
echo "$errstr ($errno)\n";
444-
die("could not bind passive port\n");
451+
} else {
452+
$pasv_port=1234;
445453
}
446454

447455
$p2 = $pasv_port % ((int) 1 << 8);
448456
$p1 = ($pasv_port-$p2)/((int) 1 << 8);
449457
fputs($s, "227 Entering Passive Mode. (127,0,0,1,{$p1},{$p2})\r\n");
450458

451-
$pasvs = stream_socket_accept($soc,10);
459+
if (empty($bug73457)) {
460+
$pasvs = stream_socket_accept($soc,10);
461+
}
452462

453463
} elseif (preg_match('/^EPSV/', $buf, $matches)) {
454464
fputs($s, "550 Extended passsive mode not supported.\r\n");
@@ -518,7 +528,9 @@ if ($pid) {
518528

519529
fputs($s, "226 Closing data Connection.\r\n");
520530
fclose($fs);
521-
}else {
531+
}elseif (preg_match('/^SIZE \/bug73457/', $buf)) {
532+
fputs($s, "213 10\r\n");
533+
}else {
522534
fputs($s, "500 Syntax error, command unrecognized.\r\n");
523535
dump_and_exit($buf);
524536
}

ext/standard/ftp_fopen_wrapper.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa
428428
int8_t read_write = 0;
429429
char *transport;
430430
int transport_len;
431+
zend_string *error_message = NULL;
431432

432433
tmp_line[0] = '\0';
433434

@@ -555,9 +556,10 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa
555556
hoststart = resource->host;
556557
}
557558
transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", hoststart, portno);
558-
datastream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL);
559+
datastream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, &error_message, NULL);
559560
efree(transport);
560561
if (datastream == NULL) {
562+
tmp_line[0]='\0';
561563
goto errexit;
562564
}
563565

@@ -581,6 +583,7 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa
581583
php_stream_wrapper_log_error(wrapper, options, "Unable to activate SSL mode");
582584
php_stream_close(datastream);
583585
datastream = NULL;
586+
tmp_line[0]='\0';
584587
goto errexit;
585588
}
586589

@@ -600,6 +603,11 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa
600603
}
601604
if (tmp_line[0] != '\0')
602605
php_stream_wrapper_log_error(wrapper, options, "FTP server reports %s", tmp_line);
606+
607+
if (error_message) {
608+
php_stream_wrapper_log_error(wrapper, options, "Failed to set up data channel: %s", ZSTR_VAL(error_message));
609+
zend_string_release(error_message);
610+
}
603611
return NULL;
604612
}
605613
/* }}} */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #73457. Wrong error message when fopen FTP wrapped fails to open data connection
3+
--SKIPIF--
4+
<?php
5+
if (array_search('ftp',stream_get_wrappers()) === FALSE) die("skip ftp wrapper not available.");
6+
if (!function_exists('pcntl_fork')) die("skip pcntl_fork() not available.");
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$bug73457=true;
12+
require __DIR__ . "/../../../ftp/tests/server.inc";
13+
14+
$path="ftp://127.0.0.1:" . $port."/bug73457";
15+
16+
$ds=file_get_contents($path);
17+
var_dump($ds);
18+
?>
19+
==DONE==
20+
--EXPECTF--
21+
Warning: file_get_contents(ftp://127.0.0.1:%d/bug73457): failed to open stream: Failed to set up data channel: Connection refused in %s on line %d
22+
bool(false)
23+
==DONE==

0 commit comments

Comments
 (0)