Skip to content

Commit c0ae3a7

Browse files
committed
Fix #80901: Info leak in ftp extension
We ensure that inbuf is NUL terminated on `ftp_readline()` failure. Closes phpGH-6894.
1 parent 7f9183c commit c0ae3a7

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
(cmb)
1212
. Fixed bug #80972 (Memory exhaustion on invalid string offset). (girgias)
1313

14+
- FTP:
15+
. Fixed bug #80901 (Info leak in ftp extension). (cmb)
16+
1417
- pgsql:
1518
. Fixed php_pgsql_fd_cast() wrt. php_stream_can_cast(). (cmb)
1619

ext/ftp/ftp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,10 +1349,12 @@ ftp_readline(ftpbuf_t *ftp)
13491349

13501350
data = eol;
13511351
if ((rcvd = my_recv(ftp, ftp->fd, data, size)) < 1) {
1352+
*data = 0;
13521353
return 0;
13531354
}
13541355
} while (size);
13551356

1357+
*data = 0;
13561358
return 0;
13571359
}
13581360
/* }}} */

ext/ftp/tests/bug80901.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #80901 (Info leak in ftp extension)
3+
--SKIPIF--
4+
<?php
5+
require 'skipif.inc';
6+
?>
7+
--INI--
8+
log_errors_max_len=0
9+
--FILE--
10+
<?php
11+
$bug80901 = true;
12+
require 'server.inc';
13+
14+
$ftp = ftp_connect("127.0.0.1", $port);
15+
if (!$ftp) die("Couldn't connect to the server");
16+
var_dump(ftp_login($ftp, 'user', 'pass'));
17+
ftp_systype($ftp);
18+
?>
19+
--EXPECTF--
20+
bool(true)
21+
22+
Warning: ftp_systype(): **************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************** in %s on line %d

ext/ftp/tests/server.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ if ($pid) {
107107
fputs($s, "234 auth type accepted\r\n");
108108
} else {
109109
fputs($s, "666 dummy\r\n");
110+
sleep(1);
110111
fputs($s, "666 bogus msg\r\n");
111112
exit;
112113
}
@@ -197,6 +198,8 @@ if ($pid) {
197198
} elseif ($buf === "SYST\r\n") {
198199
if (isset($bug27809)) {
199200
fputs($s, "215 OS/400 is the remote operating system. The TCP/IP version is \"V5R2M0\"\r\n");
201+
} elseif (isset($bug80901)) {
202+
fputs($s, "\r\n" . str_repeat("*", 4096) . "\r\n");
200203
} else {
201204
fputs($s, "215 UNIX Type: L8.\r\n");
202205
}

0 commit comments

Comments
 (0)