Simple Machines Community Forum

SMF Development => Bug Reports => Fixed or Bogus Bugs => Topic started by: alkisg on February 18, 2007, 02:50:13 AM

Title: [3112] Serious ftp bug & the fix
Post by: alkisg on February 18, 2007, 02:50:13 AM
In Subs-Package.php, smf 1.1.2, the while condition in check_response() fails to get the response in some ftp servers:
Code (php) Select

function check_response($desired)
{
// Wait for a response that isn't continued with -, but don't wait too long.
$time = time();
do
$this->last_message = fgets($this->connection, 1024);
while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);

// Was the desired response returned?
return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
}


It only checks for the third char being different than space.
But many ftp servers send disclaimers such as:

Response: 220-
Response: ================================================
Response: *******     Disclaimer                  *******
Response: ================================================
Response:
Response: Xx xxxxxx xxx xxxxxxxx xxxxxx xxxxx


In the above ftp server, the while condition would stop the loop in either the 5th or the 6th line.
So the correct condition should check for strlen() > 4 and first letter != ' '.

The fix:
Code (php) Select

function check_response($desired)
{
// Wait for a response that isn't continued with -, but don't wait too long.
$time = time();
do
$this->last_message = fgets($this->connection, 1024);
while ( (strlen($this->last_message) < 4 || substr($this->last_message, 0, 1) == ' ' ||  substr($this->last_message, 3, 1) != ' ') && time() - $time < 5);

// Was the desired response returned?
return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
}


It took me hours to debug this and to be able to install packages in my server (with safemode=on), I hope someone finds it useful.

Keep up the good work,
Alkis
Title: Re: Serious ftp bug & the fix
Post by: vbgamer45 on February 19, 2007, 12:26:09 AM
Thanks for the post. I will add it to the list.
Title: Re: Serious ftp bug & the fix
Post by: Joshua Dickerson on April 03, 2007, 01:34:57 AM
I believe this has been worked on and should show up soon as a fix. I will bring it up to the developers.
Title: Re: Serious ftp bug & the fix
Post by: SleePy on April 03, 2007, 01:15:42 PM
Yes it was being worked on. I brought this up a while ago and the devs where working on it with me since Mac systems are one of the ones that this occurs on.
Title: Re: Serious ftp bug & the fix
Post by: alkisg on February 10, 2009, 02:50:59 PM
The bug is still there in SMF 2.0 RC.
My proposed fix is still valid, but the function is now in the "Class-Package.php" file.
Title: Re: Serious ftp bug & the fix
Post by: karlbenson on February 10, 2009, 03:01:09 PM
Thx Metallica for moving this to bug reports at my request.

Hopefully being moved to here means we can have another look at it.
Title: Re: Serious ftp bug & the fix
Post by: karlbenson on February 14, 2009, 01:14:26 PM
Added to the bug tracker
http://dev.simplemachines.org/mantis/view.php?id=3112