Re: psqlodbc.dll code questions

Поиск
Список
Период
Сортировка
От Dave Page
Тема Re: psqlodbc.dll code questions
Дата
Msg-id E7F85A1B5FF8D44C8A1AF6885BC9A0E4CC3877@ratbert.vale-housing.co.uk
обсуждение исходный текст
Список pgsql-odbc
 


From: David Vaillancourt [mailto:david.vaillancourt@polymtl.ca]
Sent: 26 October 2005 01:50
To: Dave Page
Subject: Re: psqlodbc.dll code questions

Hi Dave,

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 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:

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.
 
Hi David,
 
As a first step, I've fixed a bug that caused the driver to try to write an output connection string, even if the app set the max length to zero. This could only be seen in Unicode mode. Please try the attached patch to the driver and let me know how you get on.
 
I've committed this change anyway as this is definately a bug - it just might not be entirely what you are seeing.
 
Regards, Dave
Вложения

В списке pgsql-odbc по дате отправления:

Предыдущее
От: "Dave Page"
Дата:
Сообщение: Re: Fix for Declare/Fetch issue
Следующее
От: Carlos Benkendorf
Дата:
Сообщение: Snaphost or MSI?