X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CEDC5DABC4 for ; Sat, 29 Oct 2005 10:53:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98354-08 for ; Sat, 29 Oct 2005 13:53:46 +0000 (GMT) Received: from tomts40-srv.bellnexxia.net (tomts40.bellnexxia.net [209.226.175.97]) by svr1.postgresql.org (Postfix) with ESMTP id BA29DDA123 for ; Sat, 29 Oct 2005 10:53:48 -0300 (ADT) Received: from [127.0.0.1] ([65.94.181.22]) by tomts40-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20051029135352.WYMH1799.tomts40-srv.bellnexxia.net@[127.0.0.1]> for ; Sat, 29 Oct 2005 09:53:52 -0400 Message-ID: <43637E87.4030002@sympatico.ca> Date: Sat, 29 Oct 2005 09:52:07 -0400 From: David Vaillancourt User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-odbc@postgresql.org Subject: Buffer ovverun and stack corruption Content-Type: multipart/alternative; boundary="------------030908030002090805040701" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200511/35 X-Sequence-Number: 6272 This is a multi-part message in MIME format. --------------030908030002090805040701 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Well, followed your advice and installed the package: http://wwwmaster.postgresql.org/download/mirrors-ftp?file=odbc%2Fversions%2Fsnapshots%2F*psqlodbc-08_01_0005.zip *After which I created the Windows ODBC Source (The Unicode Driver) for my application to connect to. But I still get a buffer ovverrun and stack corruption that I was getting originally. Here are some specs: 1) My machine Windows 2k server (Both app and DB are one the same box). 2) PostgreSQL Database Server 8.0.0-beta3-dev1 ( With a valid DB created in UNICODE). 3) My application uses ODBC through MFC's CDatabase and CRecordset (App is UNICODE built). Upon connection I get a buffer overrun and stack corruption. Although when I compile my App in MBCS, all seems to work Ok. As I've told you, I download the source of the Driver and had been able to do a fix for it, and it seems to work perfectly. Here's the line where it all happens in my app: // My application trying to connect to the Db CDatabase synsoftDb; synsoftDb.OpenEx( _T("DSN=PostgreSQL;DATABASE=synsoftdb;SERVER=localhost;PORT=5432;UID=someUser;PWD=SomePassword"), CDatabase::noOdbcDialog ); It looks like when I connect in UNICODE, the psqlodbc code 'sees' a big output buffer in: (From psqlodbc file : *dlg_specific.c*) makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len) { char got_dsn = (ci->dsn[0] != '\0'); char encoded_conn_settings[LARGE_REGISTRY_LEN]; UWORD hlen; /*BOOL abbrev = (len <= 400);*/ BOOL abbrev = (len < 1024); // When my app connects in MBCS len == 512, // but in Unicode len == 1024, which causes // extra data to be filled below /* fundamental info */ sprintf(connect_string, "%s=%s;DATABASE=%s;SERVER=%s;PORT=%s;UID=%s;PWD=%s", got_dsn ? "DSN" : "DRIVER", got_dsn ? ci->dsn : ci->drivername, ci->database, ci->server, ci->port, ci->username, ci->password); encode(ci->conn_settings, encoded_conn_settings); /* extra info */ hlen = strlen(connect_string); if (!abbrev) // This fills the buffer way more than needed, then it's converted // into wide chars and busts, thus creating corruption So for the time being I've replaced : if(!abbrev) with if(0) This way no extraneous data is written, and this seems to take care of the problem for now. I'm afraid this is a 'patch' that might not hold in other cases. Since you know the code and architecture better than I do, what do you make of this? If this isnt clear, I will try to give more detailed and structured information if needed. Your input will be greatly apprecidated. Thanks! --------------030908030002090805040701 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Well, followed your advice and installed the package:
http://wwwmaster.postgresql.org/download/mirrors-ftp?file=odbc%2Fversions%2Fsnapshots%2Fpsqlodbc-08_01_0005.zip

After which I created the Windows ODBC Source (The Unicode Driver) for my application to connect to. But I still get a buffer ovverrun
and stack corruption that I was getting originally. Here are some specs:

1) My machine Windows 2k server (Both app and DB are one the same box).
2) PostgreSQL Database Server 8.0.0-beta3-dev1 ( With a valid DB created in UNICODE).
3) My application uses ODBC through MFC's CDatabase and CRecordset (App is UNICODE built).

Upon connection I get a buffer overrun and stack corruption. Although when I compile my App in
MBCS, all seems to work Ok. As I've told you, I download the source of the Driver and had been
able to do a fix for it, and it seems to work perfectly. Here's the line where it all happens in my app:


// My application trying to connect to the Db

CDatabase synsoftDb;
synsoftDb.OpenEx(
            _T("DSN=PostgreSQL;DATABASE=synsoftdb;SERVER=localhost;PORT=5432;UID=someUser;PWD=SomePassword"),                 CDatabase::noOdbcDialog );


It looks like when I connect in UNICODE, the psqlodbc code 'sees' a big output buffer in:


(From psqlodbc file : dlg_specific.c)
makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len)
{
    char        got_dsn = (ci->dsn[0] != '\0');
    char        encoded_conn_settings[LARGE_REGISTRY_LEN];
    UWORD        hlen;
    /*BOOL        abbrev = (len <= 400);*/
    BOOL        abbrev = (len < 1024); // When my app connects in MBCS len == 512,
                                       // but in Unicode
len == 1024, which causes
                                       // extra data to be filled below

    /* fundamental info */
    sprintf(connect_string, "%s=%s;DATABASE=%s;SERVER=%s;PORT=%s;UID=%s;PWD=%s",
            got_dsn ? "DSN" : "DRIVER",
            got_dsn ? ci->dsn : ci->drivername,
            ci->database,
            ci->server,
            ci->port,
            ci->username,
            ci->password);

    encode(ci->conn_settings, encoded_conn_settings);

    /* extra info */
    hlen = strlen(connect_string);
    if (!abbrev)
    // This fills the buffer way more than needed, then it's converted
    // into wide chars and busts, thus creating corruption



So for the time being I've replaced :
    if(!abbrev)
with
    if(0)

This way no extraneous data is written, and this seems to take care of the problem for now. I'm afraid this is a 'patch' that
might not hold in other cases. Since you know the code and architecture better than I do, what do you make of this? If this
isnt clear, I will try to give more detailed and structured information if needed. Your input will be greatly apprecidated.

Thanks! --------------030908030002090805040701--