From: David Vaillancourt <david_v@sympatico.ca>
To: pgsql-odbc@postgresql.org
Subject: Buffer ovverun and stack corruption
Date: Sat, 29 Oct 2005 09:52:07 -0400
Message-ID: <43637E87.4030002@sympatico.ca> (raw)
Well, followed your advice and installed the package:
http://wwwmaster.postgresql.org/download/mirrors-ftp?file=odbc%2Fversions%2Fsnapshots%2F*psqlodbc-08...
*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!
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: david_v@sympatico.ca
Subject: Re: Buffer ovverun and stack corruption
In-Reply-To: <43637E87.4030002@sympatico.ca>
References: <43637E87.4030002@sympatico.ca>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox