Skip to content

Commit 27853f3

Browse files
author
alhudz
committed
bound host copy to its length in php_fopen_do_pasv
1 parent 8172b7e commit 27853f3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

ext/standard/ftp_fopen_wrapper.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,14 @@ static unsigned short php_fopen_do_pasv(php_stream *stream, char *ip, size_t ip_
361361
tpath++;
362362
}
363363
tpath[-1] = '\0';
364-
memcpy(ip, hoststart, ip_size);
365-
ip[ip_size-1] = '\0';
364+
/* hoststart is now NUL-terminated; copy only its length so a long 227
365+
* message can't drive the fixed-size read past the end of tmp_line */
366+
size_t hostlen = (size_t)(tpath - 1 - hoststart);
367+
if (hostlen >= ip_size) {
368+
hostlen = ip_size - 1;
369+
}
370+
memcpy(ip, hoststart, hostlen);
371+
ip[hostlen] = '\0';
366372
hoststart = ip;
367373

368374
/* pull out the MSB of the port */

0 commit comments

Comments
 (0)