To Antonio: hb_free () Pointer Overflow "€"

To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Fri May 03, 2013 6:06 pm

Buenas tardes Antonio,
Llevo varios intentos de poner en marcha el Directory por FTP y he conseguido aislar donde está el problema pero no le encuentro solución.
El problema radica en que la variable que llamo cABuffer, que es local en la función y que sirve para el intercambio de los datos con las funciones de acceso al protocolo FTP, al ser liberada da el error hb_free (...) Pointer Overflow.
No encuentro la manera de resolver el problema. He intentado hacer esa variable pública fuera y dentro de la función, pero no lo resuelve.
Te ruego me orientes a ver como solucionar el problema.
El programa arroja el error en la línea 222 en cABuffer ="", que es la siguiente a: msginfo("*Prueba* cABuffer")

Code: Select all  Expand view
#include "Fivewin.ch"
#include "fileio.ch"
#include "Struct.ch"

//
// File attributes
//

#define FILE_ATTRIBUTE_READONLY  1
#define FILE_ATTRIBUTE_HIDDEN    2
#define FILE_ATTRIBUTE_SYSTEM    4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE   32
#define FILE_ATTRIBUTE_NORMAL    128
#define FILE_ATTRIBUTE_TEMPORARY 256


//
// access types for InternetOpen()
//

#define INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
#define INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS


//
// manifests
//

#define INTERNET_INVALID_PORT_NUMBER    0           // use the protocol-specific default

#define INTERNET_DEFAULT_FTP_PORT       21          // default for FTP servers
#define INTERNET_DEFAULT_GOPHER_PORT    70          //    "     " gopher "
#define INTERNET_DEFAULT_HTTP_PORT      80          //    "     " HTTP   "
#define INTERNET_DEFAULT_HTTPS_PORT     443         //    "     " HTTPS  "
#define INTERNET_DEFAULT_SOCKS_PORT     1080        // default for SOCKS firewall servers.


//
// service types for InternetConnect()
//

#define INTERNET_SERVICE_FTP     1
#define INTERNET_SERVICE_GOPHER  2
#define INTERNET_SERVICE_HTTP    3


//
// flags for FTP
//

#define INTERNET_FLAG_TRANSFER_ASCII  1
#define INTERNET_FLAG_TRANSFER_BINARY 2


//
// file access types
//

#define GENERIC_READ  2147483648
#define GENERIC_WRITE 1073741824


function MAIN()
    local oWnd

    DEFINE WINDOW oWnd

    @ 2, 2 BUTTON "FTP Upload";
           SIZE 150,40;
           ACTION UPLOADFILE("FTPWRITEFILENEW.INI",,"/EBOC","localhost","FTP_E00","59EA03B64") OF oWnd

    @ 4, 2 BUTTON "FTP download";
           SIZE 150,40;
           ACTION DOWNLOADFILE( oWnd ) OF oWnd
           
    @ 6, 2 BUTTON "FTP Directory";
           SIZE 150,40;
           ACTION FTPDirectory( "/*.*","localhost","FTP_E00","59EA03B64" ) OF oWnd

    ACTIVATE WINDOW oWnd MAXIMIZED
return NIL


static function DOWNLOADFILE( oPrg )
    local hInternet, hConnect, hSource, hDest, nRead
    local cData := space( 1024 )

    hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
    hConnect = INTERNETCONNECT( hInternet, "localhost", INTERNET_INVALID_PORT_NUMBER, "FTP_E00","59EA03B84", INTERNET_SERVICE_FTP, 0, 0 )
    hSource = FTPOPENFILE( hConnect, "FTPWRITEFILENEW.INI", GENERIC_READ, 0, 0 )

    hDest = FCREATE( "FTPWRITEFILENEW.INI" )

    while .T.
        nRead = INTERNETREADFILE( hSource, @cData )

        if nRead = -1
            msginfo( "Download error" )
            exit
        endif

        if nRead = 0
            msginfo( "Download OK" )
            exit
        endif

        FWRITE( hDest, cData, nRead )
    enddo

    FCLOSE( hDest )

    INTERNETCLOSEHANDLE( hSource )
    INTERNETCLOSEHANDLE( hConnect )
    INTERNETCLOSEHANDLE( hInternet )
return NIL

static function UPLOADFILE(cSourceFile,cDestFile,cDestPath,cIP,cUser,cPass)
    local hInternet, hConnect, hSource, hDest, nRead
    local nBufferSize:=1024, cData := space( nBufferSize )
    local nPos := 0
    local lResult:=.F.
   
    default cDestFile := cSourceFile
    default cDestPath := ""
   
    hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
    hConnect = INTERNETCONNECT( hInternet, cIP, INTERNET_INVALID_PORT_NUMBER, cUser, cPass, INTERNET_SERVICE_FTP, 0, 0 )
    // Devuelve 0 si no ha conectado.
   
    hSource = FOPEN( cSourceFile, FO_READWRITE )

    hDest = FTPOPENFILE( hConnect, cDestPath+iif(cDestPath<>NIL,"/","")+cDestFile, GENERIC_WRITE, 0, 0 )

    //msginfo(cDestPath+iif(cDestPath<>NIL,"/","")+cDestFile)
    while .T.
        nRead = FREAD(hSource,@cData,nBufferSize)

        if nRead = -1
            msginfo( "Error reading source file" )
            exit
        endif

        if nRead = 0
           if lResult
              FCLOSE(hSource)
              msginfo( "Upload Finished OK" )
             else
              msginfo( "Upload error" )
           endif
           exit
        endif

        lResult:= INTERNETWRITEFILE( hDest, @cData, nRead )
       
        nPos += len( cData )
        //oPrg:set(nPos)
    enddo

    INTERNETCLOSEHANDLE( hDest )
    INTERNETCLOSEHANDLE( hConnect )
    INTERNETCLOSEHANDLE( hInternet )
return lResult


function FTPDirectory( cMask,cIP,cUser,cPass )
   local hFTPDir, aFiles := {}
   local oWin32FindData, cABuffer
   local i:=0

   default cMask := "*.*"

   STRUCT oWin32FindData
      MEMBER nFileAttributes  AS DWORD
      MEMBER nCreationTime    AS STRING LEN 8
      MEMBER nLastReadAccess  AS STRING LEN 8
      MEMBER nLastWriteAccess AS STRING LEN 8
      MEMBER nSizeHight       AS DWORD
      MEMBER nSizeLow         AS DWORD
      MEMBER nReserved0       AS DWORD
      MEMBER nReserved1       AS DWORD
      MEMBER cFileName        AS STRING LEN 260
      MEMBER cAltName         AS STRING LEN  14
   ENDSTRUCT

   hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
   hConnect = INTERNETCONNECT( hInternet, cIP, INTERNET_INVALID_PORT_NUMBER, cUser, cPass, INTERNET_SERVICE_FTP, 0, 0 )
   
   if hConnect != nil
      cABuffer := oWin32FindData:cBuffer
      hFTPDir = FtpFindFirstFile( hConnect, cMask, @cABuffer, 0, 0 )
      oWin32FindData:cBuffer = cABuffer
      if ! empty( oWin32FindData:cFileName )
         aadd( aFiles, { oWin32FindData:cFileName,;
                         oWin32FindData:nSizeLow } )
         oWin32FindData:cBuffer = ""
         while InternetFindNextFile( hFTPDir, @cABuffer )
            oWin32FindData:cBuffer = cABuffer
            aadd( aFiles, { oWin32FindData:cFileName,;
                            oWin32FindData:nSizeLow } )
            oWin32FindData:cBuffer = ""
         end
         oWin32FindData:cBuffer = ""
      endif
      InternetCloseHandle( hFTPDir )
   endif
   INTERNETCLOSEHANDLE( hFTPDir )
   INTERNETCLOSEHANDLE( hConnect )
   INTERNETCLOSEHANDLE( hInternet )
   
   msginfo("Bucle de pintado")
   for i=1 TO len(aFiles)
      msginfo(aFiles[i,1])
   next i

   msginfo("*Prueba* oWin32FindData")  
   oWin32FindData=""

   msginfo("*Prueba* cABuffer")
   cABuffer=""
   
   msginfo("*FIN*")
return aFiles



#pragma BEGINDUMP

#include "windows.h"
#include "wininet.h"
#include "hbapi.h"


HB_FUNC( INTERNETOPEN )
{
    hb_retnl( ( LONG ) InternetOpen( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ), hb_parnl( 5 ) ) );
}


HB_FUNC( INTERNETCLOSEHANDLE )
{
    hb_retl( InternetCloseHandle( ( HINTERNET ) hb_parnl( 1 ) ) );
}


HB_FUNC( INTERNETCONNECT )
{
    hb_retnl( ( LONG ) InternetConnect( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( INTERNET_PORT ) hb_parnl( 3 ), hb_parc( 4 ), hb_parc( 5 ), hb_parnl( 6 ), hb_parnl( 7 ), hb_parnl( 8 ) ) );
    // Devuelve 0 si no ha conectado.
}


HB_FUNC( FTPOPENFILE )
{
    hb_retnl( ( LONG ) FtpOpenFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}


HB_FUNC( FTPGETFILESIZE )
{
    DWORD nFileSizeHigh;

    hb_retnl( ( LONG ) FtpGetFileSize( ( HINTERNET ) hb_parnl( 1 ), &nFileSizeHigh ) );
}


HB_FUNC( INTERNETREADFILE )
{
    DWORD nBytesRead;

    BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );

    if ( !lSuccess )
        hb_retnl( -1 );
    else
        hb_retnl( nBytesRead );
}

HB_FUNC( INTERNETWRITEFILE )
{
    DWORD nBytesWritten;

    BOOL lSuccess = InternetWriteFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parnl( 3 ), &nBytesWritten );

    hb_retl( lSuccess );
}

HB_FUNC( FTPFINDFIRSTFILE )  
{
    hb_retnl( ( LONG ) FtpFindFirstFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( WIN32_FIND_DATA * ) hb_parc( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}

HB_FUNC( INTERNETFINDNEXTFILE )  
{
    BOOL lSuccess = InternetFindNextFile( ( HINTERNET ) hb_parnl( 1 ), ( WIN32_FIND_DATA * ) hb_parc( 2 ) ) ;
   
    hb_retl( lSuccess );
}
#pragma ENDDUMP
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Antonio Linares » Fri May 03, 2013 7:48 pm

Prueba a declararla como static, a ver si cambia el comportamiento
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sat May 04, 2013 5:58 am

Nada Antonio, ni declarándola como static al principio del programa antes del main() ni declarándola dentro de la función que la usa.
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Antonio Linares » Sat May 04, 2013 7:28 am

Si quitas esta línea:

cABuffer=""

persiste el problema ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sat May 04, 2013 4:19 pm

He hecho lo siguiente:
Delante de la declaración main() he declarado como static esa variable cABuffer.
Ahora en la primera pasada por la función FTPDirectory() no falla, pero al volver a ejecutarla en otra nueva pasada el programa falla en
la instrucción cABuffer = oWin32FindData:cBuffer

Lo que esta sucediendo es que después de ejecutar por primera vez la función:
InternetFindNextFile( hFTPDir, @cABuffer )
Cualquier asignación que se quiera hacer de la variable cABuffer ocasiona el error descrito.
cABuffer:=""

Es como si la función InternetFindNextFile( hFTPDir, @cABuffer ) le cambiara algo a la variable cABuffer y fuera imposible que la cambiase cualquier otro proceso que no fuera ella misma.

Adjunto el código completo:
Code: Select all  Expand view
#include "Fivewin.ch"
#include "fileio.ch"
#include "Struct.ch"

//
// File attributes
//

#define FILE_ATTRIBUTE_READONLY  1
#define FILE_ATTRIBUTE_HIDDEN    2
#define FILE_ATTRIBUTE_SYSTEM    4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE   32
#define FILE_ATTRIBUTE_NORMAL    128
#define FILE_ATTRIBUTE_TEMPORARY 256


//
// access types for InternetOpen()
//

#define INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
#define INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS


//
// manifests
//

#define INTERNET_INVALID_PORT_NUMBER    0           // use the protocol-specific default

#define INTERNET_DEFAULT_FTP_PORT       21          // default for FTP servers
#define INTERNET_DEFAULT_GOPHER_PORT    70          //    "     " gopher "
#define INTERNET_DEFAULT_HTTP_PORT      80          //    "     " HTTP   "
#define INTERNET_DEFAULT_HTTPS_PORT     443         //    "     " HTTPS  "
#define INTERNET_DEFAULT_SOCKS_PORT     1080        // default for SOCKS firewall servers.


//
// service types for InternetConnect()
//

#define INTERNET_SERVICE_FTP     1
#define INTERNET_SERVICE_GOPHER  2
#define INTERNET_SERVICE_HTTP    3


//
// flags for FTP
//

#define INTERNET_FLAG_TRANSFER_ASCII  1
#define INTERNET_FLAG_TRANSFER_BINARY 2


//
// file access types
//

#define GENERIC_READ  2147483648
#define GENERIC_WRITE 1073741824

static cABuffer

function MAIN()
    local oWnd

    DEFINE WINDOW oWnd

    @ 2, 2 BUTTON "FTP Upload";
           SIZE 150,40;
           ACTION UPLOADFILE("FTPWRITEFILENEW.INI",,"/EBOC","localhost","FTP_E00","59EA03B64") OF oWnd

    @ 4, 2 BUTTON "FTP download";
           SIZE 150,40;
           ACTION DOWNLOADFILE( oWnd ) OF oWnd
           
    @ 6, 2 BUTTON "FTP Directory";
           SIZE 150,40;
           ACTION FTPDirectory( "/*.*","localhost","FTP_E00","59EA03B64" ) OF oWnd

    ACTIVATE WINDOW oWnd MAXIMIZED
return NIL


static function DOWNLOADFILE( oPrg )
    local hInternet, hConnect, hSource, hDest, nRead
    local cData := space( 1024 )

    hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
    hConnect = INTERNETCONNECT( hInternet, "localhost", INTERNET_INVALID_PORT_NUMBER, "FTP_E00","59EA03B84", INTERNET_SERVICE_FTP, 0, 0 )
    hSource = FTPOPENFILE( hConnect, "FTPWRITEFILENEW.INI", GENERIC_READ, 0, 0 )

    hDest = FCREATE( "FTPWRITEFILENEW.INI" )

    while .T.
        nRead = INTERNETREADFILE( hSource, @cData )

        if nRead = -1
            msginfo( "Download error" )
            exit
        endif

        if nRead = 0
            msginfo( "Download OK" )
            exit
        endif

        FWRITE( hDest, cData, nRead )
    enddo

    FCLOSE( hDest )

    INTERNETCLOSEHANDLE( hSource )
    INTERNETCLOSEHANDLE( hConnect )
    INTERNETCLOSEHANDLE( hInternet )
return NIL

static function UPLOADFILE(cSourceFile,cDestFile,cDestPath,cIP,cUser,cPass)
    local hInternet, hConnect, hSource, hDest, nRead
    local nBufferSize:=1024, cData := space( nBufferSize )
    local nPos := 0
    local lResult:=.F.
 
    default cDestFile := cSourceFile
    default cDestPath := ""

    hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
    hConnect = INTERNETCONNECT( hInternet, cIP, INTERNET_INVALID_PORT_NUMBER, cUser, cPass, INTERNET_SERVICE_FTP, 0, 0 )
    // Devuelve 0 si no ha conectado.
   
    hSource = FOPEN( cSourceFile, FO_READWRITE )

    hDest = FTPOPENFILE( hConnect, cDestPath+iif(cDestPath<>NIL,"/","")+cDestFile, GENERIC_WRITE, 0, 0 )

    //msginfo(cDestPath+iif(cDestPath<>NIL,"/","")+cDestFile)
    while .T.
        nRead = FREAD(hSource,@cData,nBufferSize)

        if nRead = -1
            msginfo( "Error reading source file" )
            exit
        endif

        if nRead = 0
           if lResult
              FCLOSE(hSource)
              msginfo( "Upload Finished OK" )
             else
              msginfo( "Upload error" )
           endif
           exit
        endif

        lResult:= INTERNETWRITEFILE( hDest, @cData, nRead )
       
        nPos += len( cData )
        //oPrg:set(nPos)
    enddo

    INTERNETCLOSEHANDLE( hDest )
    INTERNETCLOSEHANDLE( hConnect )
    INTERNETCLOSEHANDLE( hInternet )
return lResult


function FTPDirectory( cMask,cIP,cUser,cPass )
   local hFTPDir, aFiles := {}
   local oWin32FindData //, cABuffer
   local i:=0

   default cMask := "*.*"
   
   msginfo( valtype(cABuffer) )

   STRUCT oWin32FindData
      MEMBER nFileAttributes  AS DWORD
      MEMBER nCreationTime    AS STRING LEN 8
      MEMBER nLastReadAccess  AS STRING LEN 8
      MEMBER nLastWriteAccess AS STRING LEN 8
      MEMBER nSizeHight       AS DWORD
      MEMBER nSizeLow         AS DWORD
      MEMBER nReserved0       AS DWORD
      MEMBER nReserved1       AS DWORD
      MEMBER cFileName        AS STRING LEN 260
      MEMBER cAltName         AS STRING LEN  14
   ENDSTRUCT

   hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
   hConnect = INTERNETCONNECT( hInternet, cIP, INTERNET_INVALID_PORT_NUMBER, cUser, cPass, INTERNET_SERVICE_FTP, 0, 0 )
   
   msginfo("Empieza a leer el directorio FTP")
   if hConnect != nil
      cABuffer = oWin32FindData:cBuffer
      hFTPDir = FtpFindFirstFile( hConnect, cMask, @cABuffer, 0, 0 )
      oWin32FindData:cBuffer = cABuffer
      if ! empty( oWin32FindData:cFileName )
         aadd( aFiles, { oWin32FindData:cFileName,;
                         oWin32FindData:nSizeLow } )
         oWin32FindData:cBuffer = ""
         while InternetFindNextFile( hFTPDir, @cABuffer )
            oWin32FindData:cBuffer = cABuffer
            aadd( aFiles, { oWin32FindData:cFileName,;
                            oWin32FindData:nSizeLow } )
            oWin32FindData:cBuffer = ""
         end
         oWin32FindData:cBuffer = ""
      endif
      InternetCloseHandle( hFTPDir )
   endif
   INTERNETCLOSEHANDLE( hFTPDir )
   INTERNETCLOSEHANDLE( hConnect )
   INTERNETCLOSEHANDLE( hInternet )
   
   msginfo("Bucle de pintado")
   for i=1 TO len(aFiles)
      msginfo(aFiles[i,1])
   next i

   msginfo("*Prueba* oWin32FindData")  
   oWin32FindData:=NIL

   msginfo("*Prueba* cABuffer")
   //msginfo( valtype(cABuffer) )
   //cABuffer:=NIL
   
   msginfo("*FIN*")
return aFiles



#pragma BEGINDUMP

#include "windows.h"
#include "wininet.h"
#include "hbapi.h"


HB_FUNC( INTERNETOPEN )
{
    hb_retnl( ( LONG ) InternetOpen( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ), hb_parnl( 5 ) ) );
}


HB_FUNC( INTERNETCLOSEHANDLE )
{
    hb_retl( InternetCloseHandle( ( HINTERNET ) hb_parnl( 1 ) ) );
}


HB_FUNC( INTERNETCONNECT )
{
    hb_retnl( ( LONG ) InternetConnect( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( INTERNET_PORT ) hb_parnl( 3 ), hb_parc( 4 ), hb_parc( 5 ), hb_parnl( 6 ), hb_parnl( 7 ), hb_parnl( 8 ) ) );
    // Devuelve 0 si no ha conectado.
}


HB_FUNC( FTPOPENFILE )
{
    hb_retnl( ( LONG ) FtpOpenFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}


HB_FUNC( FTPGETFILESIZE )
{
    DWORD nFileSizeHigh;

    hb_retnl( ( LONG ) FtpGetFileSize( ( HINTERNET ) hb_parnl( 1 ), &nFileSizeHigh ) );
}


HB_FUNC( INTERNETREADFILE )
{
    DWORD nBytesRead;

    BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );

    if ( !lSuccess )
        hb_retnl( -1 );
    else
        hb_retnl( nBytesRead );
}

HB_FUNC( INTERNETWRITEFILE )
{
    DWORD nBytesWritten;

    BOOL lSuccess = InternetWriteFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parnl( 3 ), &nBytesWritten );

    hb_retl( lSuccess );
}

HB_FUNC( FTPFINDFIRSTFILE )  
{
    hb_retnl( ( LONG ) FtpFindFirstFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( WIN32_FIND_DATA * ) hb_parc( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}

HB_FUNC( INTERNETFINDNEXTFILE )  
{
    BOOL lSuccess = InternetFindNextFile( ( HINTERNET ) hb_parnl( 1 ), ( WIN32_FIND_DATA * ) hb_parc( 2 ) ) ;
   
    hb_retl( lSuccess );
}
#pragma ENDDUMP
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sat May 04, 2013 4:42 pm

He metido el parche, porque no creo que se le pueda llamar de otra manera, que te comento y con eso se ha evitado el problema, aunque no me quedo conforme con esta solución:

Para evitar tener que asignar el tamaño a cABuffer mediante la instrucción cABuffer = oWin32FindData:cBuffer, que es lo que provoca el error en la segunda pasada de la función, lo que he hecho ha sido asignar un tamaño a cABuffer justo después de main(). En concreto le he puesto cABuffer = space(500).

Code: Select all  Expand view
static cABuffer

function MAIN()
    local oWnd
    cABuffer = space(500)
   
    DEFINE WINDOW oWnd


Como con esto ya no hay que volver a poner en ninguna parte cABuffer = a algo, el problema se elimina.
Sin embargo, la instrucción: InternetFindNextFile( hFTPDir, @cABuffer ) si que sigue usando -modificando el contenido- la dirección de memoria correspondiente a cABuffer, siendo por ello que deduzco que, según parece, ese espacio de memoria correspondiente a cABuffer, una vez es usado por primera vez por la instrucción InternetFindNextFile( hFTPDir, @cABuffer ), queda reservado para su uso y disfrute en exclusiva. Sin que pueda ser usado, ni siquiera para liberarlo, por ninguna otra parte del programa.
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Antonio Linares » Sat May 04, 2013 4:53 pm

Prueba a cambiar esta función asi:

Code: Select all  Expand view
HB_FUNC( INTERNETFINDNEXTFILE )  
{
    WIN32_FIND_DATA fd;

    memcpy( ( void * ) &fd, ( void * ) hb_parc( 2 ), sizeof( WIN32_FIND_DATA ) );
   
    hb_retl( InternetFindNextFile( ( HINTERNET ) hb_parnl( 1 ), &fd );
    hb_storclen( 2, ( char * ) fd, sizeof( WIN32_FIND_DATA ) );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sat May 04, 2013 5:10 pm

Antonio,
Lo de poner space(500) ha sido para que cupiesen de sobra los datos que devuelve InternetFindNextFile porque si se pone menos da error al salir del programa.
No obstante, para apurar exacto el tamaño se puede hacer definiendo una nueva función que nos devuelva el tamaño de esa estructura de datos que es WIN32_FIND_DATA, con lo siguiente:

Defino una función que calcule el tamaño, por ejemplo:

Code: Select all  Expand view

HB_FUNC( SIZEOFFTPDIRECTORYDATA )
{
    hb_retnl( sizeof(WIN32_FIND_DATA) ) ;
}


y en vez de poner cABuffer=space(500) pongo: cABuffer = space( space( SIZEOFFTPDIRECTORYDATA() ) )
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sat May 04, 2013 5:22 pm

Con los cambios que me has indicado al compilar arroja los siguientes errores:

Macro expansion too long in function HB_FUNC_INTERNETFINDNEXTFILE
Wrong number of arguments in call of macro hb_retl in function HB_FUNC_INTERNETFINDNEXTFILE
Compound statement missing } in function HB_FUNC_INTERNETFINDNEXTFILE
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sat May 04, 2013 5:34 pm

Antonio,
Faltaba un paréntesis y por eso arrojaba esos errores. Una vez corregido arroja estos otros:

Incompatible type conversion in function HB_FUNC_INTERNETFINDNEXTFILE - en la línea: hb_storclen( 2, ( char * ) fd, sizeof( WIN32_FIND_DATA ) )
Type mismatch in parameter 'szText' wanted 'signed char *', got int. in function HB_FUNC_INTERNETFINDNEXTFILE
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Antonio Linares » Sat May 04, 2013 6:16 pm

Disculpa, me equivoqué en el orden de los parámetros al llamar a storclen(), este orden es el correcto:

hb_storclen( ( char * ) fd, sizeof( WIN32_FIND_DATA ), 2 );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sun May 05, 2013 8:04 am

Ahora al compilar devuelve el error : incompatible type conversion
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Antonio Linares » Sun May 05, 2013 8:52 am

Faltaba la dirección &

hb_storclen( ( char * ) &fd, sizeof( WIN32_FIND_DATA ), 2 );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Verhoven » Sun May 05, 2013 9:14 am

Ahora es peor todavía. El error hb_free Pointer Overflow lo arroja a la primera que se hace una llamada a la funcion InternetFindNextFile. Tanto si declaro cABuffer como static al principio del programa como si la declaro como local dentro de la funcion que la usa.
Verhoven
 
Posts: 505
Joined: Sun Oct 09, 2005 7:23 pm

Re: To Antonio: hb_free () Pointer Overflow "€"

Postby Antonio Linares » Sun May 05, 2013 9:39 am

Prueba a comentar esta línea y dime si se elimina ese nuevo error:

Code: Select all  Expand view
HB_FUNC( INTERNETFINDNEXTFILE )  
{
    WIN32_FIND_DATA fd;

    memcpy( ( void * ) &fd, ( void * ) hb_parc( 2 ), sizeof( WIN32_FIND_DATA ) );
   
    hb_retl( InternetFindNextFile( ( HINTERNET ) hb_parnl( 1 ), &fd );
    // hb_storclen( ( char * ) &fd, sizeof( WIN32_FIND_DATA ), 2 );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests