PHP 4.0 Bug #7245: ftp_rawlist fix

From: Date: Mon, 16 Oct 2000 14:53:19 +0000
Subject: PHP 4.0 Bug #7245: ftp_rawlist fix
Groups: php.dev 
Request: Send a blank email to php-dev+get-35133@lists.php.net to get a copy of this message
From: rxdev@serianet.com Operating system: Linux 2.2.17 PHP version: 4.0.3pl1 PHP Bug Type: FTP related Bug description: ftp_rawlist fix 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 -- Edit Bug report at: http://bugs.php.net/?id=7245&edit=1

« previous php.dev (#35133) next »