|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-10-28 04:55 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 16:00:01 2025 UTC |
ftp_rawlist() bug: ----------------- The function ftp_rawlist() is not properly working when you want to list the current directory without naming it (i.e. 'LIST' command without parameters), e.g. $arr=ftp_rawlist($fp,"") is not working properly because PHP generates the command 'LIST ' (with supplemental space after LIST) which is NOT recognized by many ftp servers. The empty path (that should mean "current directory") is absolutely necessary as: * ftp_rawlist($fp,".") or ftp_rawlist($fp,"./") lists RECURSIVELY the directory on many ftpd servers : you can not use it to list the CWD * rawlist($fp,<absolute path>) does NOT work with symlinks (the LIST <symlink> lists the symlink itself!) on many other ftpd servers The only temporary trick to list the current directory in raw mode is to do a ftp_rawlist($fp,"-l") that generate a LIST -l However, this is only a trick and therefore ftp_rawlist($fp,"") should be accepted Here comes the reason of this bug, and the fix: In ext/ftp/php_ftp.c you have the function PHP_FUNCTION(ftp_rawlist) defined, and this function calls the following subfunctions: PHP_FUNCTION(ftp_rawlist) -> llist = ftp_list(ftp, arg2->value.str.val); -> ftp_list(ftpbuf_t *ftp, const char *path) -> ftp_genlist(ftp, "LIST", path); -> if (!ftp_putcmd(ftp, cmd, path)) -> this one has a BUG The bug is located in file ext/ftp/ftp.c, function ftp_putcmd() : int ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args) { int size; char *data; /* build the output buffer */ if (args) { /* "cmd args\r\n\0" */ if (strlen(cmd) + strlen(args) + 4 > FTP_BUFSIZE) return 0; size = sprintf(ftp->outbuf, "%s %s\r\n", cmd, args); It would be GREAT to put instead: /* "cmd args\r\n\0" */ if (strlen(cmd) + strlen(args) + 4 > FTP_BUFSIZE) return 0; if (args[0]) size = sprintf(ftp->outbuf, "%s %s\r\n", cmd, args); else size = sprintf(ftp->outbuf, "%s\r\n", cmd); Because currently, the sprintf(ftp->outbuf, "%s %s\r\n", cmd, args); generates a supplemental space ' ' when args is empty Regards, Xavier Roche rxdev@serianet.com Serianet.Com