pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedECPG segfault
3+ messages / 3 participants
[nested] [flat]
* ECPG segfault
@ 2004-03-26 12:26 Jürgen Cappel <email@juergen-cappel.de>
2004-03-29 15:13 ` Re: ECPG segfault Michael Meskes <meskes@postgresql.org>
2004-03-29 15:26 ` Re: ECPG segfault Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 2 replies; 3+ messages in thread
From: Jürgen Cappel @ 2004-03-26 12:26 UTC (permalink / raw)
To: pgsql-interfaces
The code in ecpg/preproc/type.c has a problem when allocating
memory. I'm referring to the function ECPGdump_a_simple() where
one of the first actions is allocating memory and assigning it
to variable "offset". The amount of memory requested depends on
the size of the variable's name and the length of a fixed string.
The function has a parameter called "varcharsize" (array size string)
which is later used in the "case ECPGt_char:" where it is included
in an sprintf() to fill the allocated memory area. This leads to
a subsequent segmentation fault if "varcharsize" is not a simple
integer but maybe a cpp macro of some length, say, 20 bytes. At
least it *can* lead to a segfault, because you never know how and
when memory corruption strikes back on you ...
Using my example, things work well when allocating a few bytes more,
but i would suggest adding a strlen(varcharsize) instead of 1 byte
for allocation of "offset".
Comments are welcome ! Best regards, Jürgen Cappel
Oh, and btw thanks to valgrind for pointing me to that place :-)
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ECPG segfault
2004-03-26 12:26 ECPG segfault Jürgen Cappel <email@juergen-cappel.de>
@ 2004-03-29 15:13 ` Michael Meskes <meskes@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Michael Meskes @ 2004-03-29 15:13 UTC (permalink / raw)
To: Jürgen Cappel <email@juergen-cappel.de>; +Cc: pgsql-interfaces
Thanks for hunting down this bug. Patch applied to HEAD and 7.4.
On Fri, Mar 26, 2004 at 01:26:28PM +0100, Jürgen Cappel wrote:
> Using my example, things work well when allocating a few bytes more,
> but i would suggest adding a strlen(varcharsize) instead of 1 byte
> for allocation of "offset".
Actually you need the 1 too. :-)
Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ECPG segfault
2004-03-26 12:26 ECPG segfault Jürgen Cappel <email@juergen-cappel.de>
@ 2004-03-29 15:26 ` Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 0 replies; 3+ messages in thread
From: Bruce Momjian @ 2004-03-29 15:26 UTC (permalink / raw)
To: Jürgen Cappel <email@juergen-cappel.de>; +Cc: pgsql-interfaces
Michael has fixed this in 7.4.X and CVS HEAD. Thanks.
---------------------------------------------------------------------------
Jürgen Cappel wrote:
> The code in ecpg/preproc/type.c has a problem when allocating
> memory. I'm referring to the function ECPGdump_a_simple() where
> one of the first actions is allocating memory and assigning it
> to variable "offset". The amount of memory requested depends on
> the size of the variable's name and the length of a fixed string.
> The function has a parameter called "varcharsize" (array size string)
> which is later used in the "case ECPGt_char:" where it is included
> in an sprintf() to fill the allocated memory area. This leads to
> a subsequent segmentation fault if "varcharsize" is not a simple
> integer but maybe a cpp macro of some length, say, 20 bytes. At
> least it *can* lead to a segfault, because you never know how and
> when memory corruption strikes back on you ...
>
> Using my example, things work well when allocating a few bytes more,
> but i would suggest adding a strlen(varcharsize) instead of 1 byte
> for allocation of "offset".
>
> Comments are welcome ! Best regards, J?rgen Cappel
>
> Oh, and btw thanks to valgrind for pointing me to that place :-)
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-03-29 15:26 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-03-26 12:26 ECPG segfault Jürgen Cappel <email@juergen-cappel.de>
2004-03-29 15:13 ` Michael Meskes <meskes@postgresql.org>
2004-03-29 15:26 ` Bruce Momjian <pgman@candle.pha.pa.us>
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