Home > Archive > PostgeSQL ODBC > November 2005 > Buffer ovverun and stack corruption









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Buffer ovverun and stack corruption
David Vaillancourt

2005-11-04, 3:23 am

Well, followed your advice and installed the package:
http://wwwmaster.postgresql.org/dow...-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;DATAB
ASE=synsoftdb;SERVER
=localhost;PORT=5432
;UID=someUser;PWD=So
mePassword"),
CDatabase::noOdbcDia
log );


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


(From psqlodbc file : *dlg_specific.c*)
makeConnectString(ch
ar *connect_string, const ConnInfo *ci, UWORD len)
{
char got_dsn = (ci->dsn[0] != '\0');
char encoded_conn_setting
s& #91;LARGE_REGISTRY_L
EN];
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_stri
ng,
" %s=%s;DATABASE=%s;SE
RVER=%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_setting
s);

/* extra info */
hlen = strlen(connect_strin
g);
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!

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com