Skip site navigation (1) Skip section navigation (2)

Buffer ovverun and stack corruption

From: David Vaillancourt <david_v(at)sympatico(dot)ca>
To: pgsql-odbc(at)postgresql(dot)org
Subject: Buffer ovverun and stack corruption
Date: 2005-10-29 13:52:07
Message-ID: (view raw or whole thread)
Lists: pgsql-odbc
Well, followed your advice and installed the package:*

*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 
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;
                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 */
            got_dsn ? "DSN" : "DRIVER",
            got_dsn ? ci->dsn : ci->drivername,

    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 :

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.


pgsql-odbc by date

Next:From: Alex JiangDate: 2005-10-29 14:01:50
Subject: TQuery not showing new columns
Previous:From: Leendert Paul DiterwichDate: 2005-10-28 08:39:06
Subject: Postgresql odbc driver 7.3+ Visual Studio .Net

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group