• Welcome to Simple Machines Community Forum. Please login or sign up.
December 07, 2021, 03:57:05 PM

News:

SMF 2.0.18 has been released! Please update. Read more.


[3112] Serious ftp bug & the fix

Started by alkisg, February 18, 2007, 02:50:13 AM

Previous topic - Next topic

alkisg

February 18, 2007, 02:50:13 AM Last Edit: May 11, 2009, 07:04:35 PM by SleePy
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

vbgamer45

Thanks for the post. I will add it to the list.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Joshua Dickerson

I believe this has been worked on and should show up soon as a fix. I will bring it up to the developers.
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

SleePy

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.
Jeremy D — Site Team / SMF Developer
Support the SMF Support team!
Profiles:GitHub
Join us on IRC Libera.chat/#smf

alkisg

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.

karlbenson

Thx Metallica for moving this to bug reports at my request.

Hopefully being moved to here means we can have another look at it.

karlbenson


Advertisement: