php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7245 ftp_rawlist fix
Submitted: 2000-10-16 10:53 UTC Modified: 2000-10-28 04:55 UTC
From: rxdev at serianet dot com Assigned:
Status: Closed Package: FTP related
PHP Version: 4.0.3pl1 OS: Linux 2.2.17
Private report: No CVE-ID: None
 [2000-10-16 10:53 UTC] rxdev at serianet dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-28 04:55 UTC] sniper@php.net
Fixed in CVS. Thank you for this very good bug report! 

--Jani
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC