Bug with Windows FTP functions ?

Bug with Windows FTP functions ?

Post by Valentin K » Mon, 14 Mar 2005 02:33:16


'am working on a very little FTP client and since the beginning, I have a
very strange bug that crashes my application. The bug produces when I would
like to display a directory. But not the first time and only if a automatic
variable is used before the second call.

I made several checks and tests:

- Insulate the application into a Console Application with the
minimum necessary : always the same error (under WinXP with the last version
of LCC)

- Compile under DevC++ : It Works! (under WinXP)

- Compile under an older version of LCC on Windows98 : It Works!

- Compile with these same version under WinXP : Error

- Execute the program compiled under Win98 on WinXP : it Works!!



My diagnostic is :

There is a bug, apparently not in my code, which make an error on the
application stack. Where could be the error???



Thank you very much for your help.



Valentin KIELBASA



Here below the source and you can found the full project at this address:

http://www.phidus.net/ftpbug/testFTP.zip





#include <windows.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>



#include "ftp.h"





int main(void)

{

HINTERNET g_ftphdl;

char buffer[512];



g_ftphdl = FTP_CreateSession("ftp.free.fr", "anonymous", "",
21);

if(g_ftphdl == 0)

{

printf("\nERREUR : Impossible de se connecter ? l'he");

return 1;

}



FTP_DisplayDir(g_ftphdl, INTERNET_FLAG_RELOAD, 0);





while(1)

{

printf("\n> change directory for : ");

fgets(buffer, sizeof(buffer)-1, stdin);



FTP_ChangeDir(g_ftphdl, buffer);



FTP_DisplayDir(g_ftphdl, INTERNET_FLAG_RELOAD, 0);



}



return 0;

}



/*------------------------------------------------------------------------

Procedure: createFtpSession ID:1

Purpose: Cr une session FTP

Input: serveur

user

password

port : Si = 0, port par daut cad

INTERNET_DEFAULT_FTP_PORT

Output: Structure de type HINTERNET

Errors:

------------------------------------------------------------------------*/

HINTERNET FTP_CreateSession(char *serveur, char *user, char *pass, int port)

{

/********************************************************

* Dlaration de variables

********************************************************/

HINTERNET hOpenHandle, hConnectHandle;





/********************************************************

* Code

********************************************************/



if(port == 0) port = INTERNET_DEFAULT_FTP_PORT;



hOpenHandle = InternetOpen("FTPManager",
INTERNET_OPEN_TYPE_PRECONFIG,

NULL, NULL, 0);



hConnectHandle = InternetConnect(hOpenHandle, serveur,

port, user,

pass, INTERNET_SERVICE_FTP,0,0);



return hConnectHandle;

}







/*------------------------------------------------------------------------

Procedure: Displ
 
 
 

Bug with Windows FTP functions ?

Post by F. Fritsch » Mon, 14 Mar 2005 04:31:47

On Sat, 12 Mar 2005 18:33:16 +0100, "Valentin KIELBASA"


Did you try to hunt it down with the de *** ? (This way you could
exactly tell us w h e r e the program crashes in the code.)

Btw: Could you be a little bit more specific concerning the circum-
stances of the crash? What did you do _exactly_? (In your demo code the
function "FTP_ChangeDir()" was missing. Used the code from ftp.c, but no
crash on my machine - Windows 2000).


F.

 
 
 

Bug with Windows FTP functions ?

Post by jacob navi » Mon, 14 Mar 2005 04:39:19

I compiled this, and it works, at least it doesn't crash at all.

You could tell us where it crashes???

jacob
 
 
 

Bug with Windows FTP functions ?

Post by Valentin K » Mon, 14 Mar 2005 05:29:56


Yes, I tried with the de *** and I have any crash. BUT the directory list
is not the full list!!!







So, here is my loop:

while(1)

{

printf("\n> change directory for : ");

fgets(buffer, sizeof(buffer)-1, stdin);

printf("(enter)"); // <<<< CRASH BEFORE HERE



FTP_ChangeDir(g_ftphdl, buffer);



FTP_DisplayDir(g_ftphdl, INTERNET_FLAG_RELOAD, 0);



}



In the console window I have :

Entree

logs

lost+found

mirrors

mirrors1

mirrors2

pub

stats

tmp




I type tmp and "return" and the program crashes. (without printing
"(enter)")





(sorry,the FTP_ChangeDir() function wad missing. but you have take the good
one)



If it works for you, it's very strange. I can't undestand.



Valentin



42334563$0$1239$ XXXX@XXXXX.COM ...
 
 
 

Bug with Windows FTP functions ?

Post by F. Fritsch » Tue, 15 Mar 2005 05:57:36

On Sat, 12 Mar 2005 21:29:56 +0100, "Valentin KIELBASA"


Huh? You mean you _don't_ have any crash? Or you d o have _a_ crash?
(Sorry, cant' parse your statement right now.)

Which directory list? You mean the one _produced by your program_?
- So w h a t _does_ it produce and w h a t _should it_ produce?


Strange thing. One might suspect that it's the fgets(). A problem with
buffer? But if buffer is just an array of chars it should certainly
work, I think. (BTW: You may use "sizeof(buffer)" as argument instead
of "sizeof(buffer)-1". Then fgets() just reads in max. sizeof(buffer)-1
chars and appends a '\0'.)

Hm, *I* only got

logs
lost+found

Well...

Pffff... Can't reproduce this here on my machine (Windows 2000).

Ok.

Same for me. :-?

But actually, I didn't check the code VERY intensive (I mean every
single line). May be the reason for the crash is located some lines
earlier in the code!

I'm not really convinced that it's a problem related to lcc-win32 - but
it certainly m i g h t be. [...]


F.
 
 
 

Bug with Windows FTP functions ?

Post by Valentin K » Wed, 16 Mar 2005 05:52:32


XXXX@XXXXX.COM ...


Excuse me, I don't write a very good english :-(
I have NO crash with the de *** and... when only optimization is UNCHECKED
I have the same behavior : program don't crash but the directory list is not
full...



the directory list is the list of the Free.fr FTP which is :
logs
lost+found
mirrors
mirrors1
mirrors2
pub
stats
tmp




At the beginning, it was a Windows application (with GUI). So, there was any
fgets.


So!! You Have the ERROR!!!! Have you cheked the Optimization? Try with
optimization checked
Your ftp directory list is not the full list...

Thank you very much for your help

Valentin KIELBASA