pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSQLGetInfo Bug
5+ messages / 2 participants
[nested] [flat]
* SQLGetInfo Bug
@ 2003-01-02 12:50 Dave Page <dpage@vale-housing.co.uk>
2003-01-02 14:35 ` Re: SQLGetInfo Bug Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Dave Page @ 2003-01-02 12:50 UTC (permalink / raw)
To: pgsql-odbc; +Cc: Didier Moens <moensd@xs4all.be>
I've been working with Didier Moens to try to fix the bug detailed at https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=80394.
As I said towards the end, the error is caused by an overflow of the tmp buffer in PGAPI_GetInfo in info.c for which I have committed a change doubling it's size to 256 bytes. I also tried using snprintf instead of sprintf for safety:
snprintf(tmp, sizeof(tmp) - 1, "%s %s", POSTGRESDRIVERVERSION, conn->pg_version);
but somewhere along the way garbage is getting appended back on the string returned:
[328][SQLGetInfo][328]PGAPI_GetInfo: entering...fInfoType=18
[328]PGAPI_GetInfo: p='07.02.0005 PostgreSQL 7.3 on i386-redhat-linux-gnu, compiled by GCC i386-redhat-linux-gcc (GCC) 3.2.1 20021207 (Red Hat Linux 8wãF¸8Ù', len=0, value=0, cbMax=0
I can't see what the heck I've done wrong here. Any ideas?
Cheers, Dave.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQLGetInfo Bug
2003-01-02 12:50 SQLGetInfo Bug Dave Page <dpage@vale-housing.co.uk>
@ 2003-01-02 14:35 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2003-01-02 14:35 UTC (permalink / raw)
To: Dave Page <dpage@vale-housing.co.uk>; +Cc: pgsql-odbc; Didier Moens <moensd@xs4all.be>
"Dave Page" <dpage@vale-housing.co.uk> writes:
> snprintf(tmp, sizeof(tmp) - 1, "%s %s", POSTGRESDRIVERVERSION, conn->pg_version);
> but somewhere along the way garbage is getting appended back on the string returned:
> [328][SQLGetInfo][328]PGAPI_GetInfo: entering...fInfoType=18
> [328]PGAPI_GetInfo: p='07.02.0005 PostgreSQL 7.3 on i386-redhat-linux-gnu, compiled by GCC i386-redhat-linux-gcc (GCC) 3.2.1 20021207 (Red Hat Linux 8wãF¸8Ù', len=0, value=0, cbMax=0
> I can't see what the heck I've done wrong here. Any ideas?
I think the error is elsewhere, and that the garbage is already present
in conn->pg_version.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQLGetInfo Bug
@ 2003-01-02 14:47 Dave Page <dpage@vale-housing.co.uk>
2003-01-02 15:03 ` Re: SQLGetInfo Bug Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Dave Page @ 2003-01-02 14:47 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-odbc; Didier Moens <moensd@xs4all.be>
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: 02 January 2003 14:36
> To: Dave Page
> Cc: pgsql-odbc@postgresql.org; Didier Moens
> Subject: Re: [ODBC] SQLGetInfo Bug
>
>
> "Dave Page" <dpage@vale-housing.co.uk> writes:
> > snprintf(tmp, sizeof(tmp) - 1, "%s %s", POSTGRESDRIVERVERSION,
> > conn->pg_version);
>
> > but somewhere along the way garbage is getting appended back on the
> > string returned:
>
> > [328][SQLGetInfo][328]PGAPI_GetInfo: entering...fInfoType=18
> > [328]PGAPI_GetInfo: p='07.02.0005 PostgreSQL 7.3 on
> > i386-redhat-linux-gnu, compiled by GCC i386-redhat-linux-gcc (GCC)
> > 3.2.1 20021207 (Red Hat Linux 8wãF¸8Ù', len=0, value=0, cbMax=0
>
> > I can't see what the heck I've done wrong here. Any ideas?
>
> I think the error is elsewhere, and that the garbage is
> already present in conn->pg_version.
Hi Tom,
The garbage is not there if I use sprintf with a larger size of tmp. I've tried variations of the code to check (without luck) but I assume I'm not somehow knocking the null off the end of the string?
Also of note, is that the logging call from which I'm seeing the garbage occurs before any other manipulation of the string.
Regards, Dave.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQLGetInfo Bug
2003-01-02 14:47 Re: SQLGetInfo Bug Dave Page <dpage@vale-housing.co.uk>
@ 2003-01-02 15:03 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2003-01-02 15:03 UTC (permalink / raw)
To: Dave Page <dpage@vale-housing.co.uk>; +Cc: pgsql-odbc; Didier Moens <moensd@xs4all.be>
"Dave Page" <dpage@vale-housing.co.uk> writes:
> The garbage is not there if I use sprintf with a larger size of
> tmp. I've tried variations of the code to check (without luck) but I
> assume I'm not somehow knocking the null off the end of the string?
You would be losing the trailing null if the snprintf is unable to fit
its output into the buffer size it's told to use (at least, that's how
most implementations of snprintf react, I think).
It doesn't look like this should be enough data to overrun your buffer,
but I don't have a better theory at the moment.
Perhaps
snprintf(tmp, sizeof(tmp) - 1, "%s %s", ...);
tmp[sizeof(tmp) - 1] = '\0';
would be better coding practice if you don't want to actually check
snprintf's result.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: SQLGetInfo Bug
@ 2003-01-02 15:31 Dave Page <dpage@vale-housing.co.uk>
0 siblings, 0 replies; 5+ messages in thread
From: Dave Page @ 2003-01-02 15:31 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-odbc; Didier Moens <moensd@xs4all.be>
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: 02 January 2003 15:03
> To: Dave Page
> Cc: pgsql-odbc@postgresql.org; Didier Moens
> Subject: Re: [ODBC] SQLGetInfo Bug
>
>
> "Dave Page" <dpage@vale-housing.co.uk> writes:
> > The garbage is not there if I use sprintf with a larger
> size of tmp.
> > I've tried variations of the code to check (without luck)
> but I assume
> > I'm not somehow knocking the null off the end of the string?
>
> You would be losing the trailing null if the snprintf is
> unable to fit its output into the buffer size it's told to
> use (at least, that's how most implementations of snprintf
> react, I think).
>
> It doesn't look like this should be enough data to overrun
> your buffer, but I don't have a better theory at the moment.
>
> Perhaps
>
> snprintf(tmp, sizeof(tmp) - 1, "%s %s", ...);
> tmp[sizeof(tmp) - 1] = '\0';
>
> would be better coding practice if you don't want to actually
> check snprintf's result.
Thanks Tom, that got it.
Regards, Dave.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-01-02 15:31 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-01-02 12:50 SQLGetInfo Bug Dave Page <dpage@vale-housing.co.uk>
2003-01-02 14:35 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-01-02 14:47 Re: SQLGetInfo Bug Dave Page <dpage@vale-housing.co.uk>
2003-01-02 15:03 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-01-02 15:31 Re: SQLGetInfo Bug Dave Page <dpage@vale-housing.co.uk>
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