| Lists: | pgsql-hackers | 
|---|
| From: | "Rader, David" <davidr(at)openscg(dot)com> | 
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | [PATCH] ECPG bug fix in preproc when indicator struct is shorter than record struct | 
| Date: | 2018-01-11 16:47:52 | 
| Message-ID: | CAABt7R5qCGtzQe=suioG5OVWOA5jw2mvRx41VnxhBLgAvY6vKA@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Lists: | pgsql-hackers | 
Hello -
Attached is a proposed patch to fix a bug in the ECPG preprocessor that
generates application code that core dumps at run-time. When the input pgc
code uses a record struct for returning query results and uses an indicator
struct that has fewer fields than the record struct, the generated .c code
will compile with no warning but core dump. This situation comes up when a
developer adds a field to an existing query, adds the field to the record
struct and forgets to add the field to the indicator struct.
The patch fixes the generated code to use ECPGt_NO_INDICATOR in the call to
ecpglib for indicator members that are not present and issues a compiler
warning for either too few indicator members or too many indicator members.
The attached sample files are a simple sample of pgc code that can be used
to see the difference in before and after generation and the before and
after generated code.
If accepted, this bug fix can be back ported to earlier versions of ecpg as
well.
Thanks
Dave
| Attachment | Content-Type | Size | 
|---|---|---|
| 0001-Fix-generated-code-to-avoid-core-dump-when-indicator.patch | text/x-patch | 1.3 KB | 
| indrecs.c | text/x-csrc | 8.9 KB | 
| indrecs.c.fix | application/octet-stream | 7.3 KB | 
| indrecs.pgc | application/octet-stream | 2.6 KB | 
| From: | Michael Meskes <meskes(at)postgresql(dot)org> | 
|---|---|
| To: | "Rader, David" <davidr(at)openscg(dot)com>, pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: [PATCH] ECPG bug fix in preproc when indicator struct is shorter than record struct | 
| Date: | 2018-01-13 14:02:16 | 
| Message-ID: | [email protected] | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Lists: | pgsql-hackers | 
> Attached is a proposed patch to fix a bug in the ECPG preprocessor
> that generates application code that core dumps at run-time. When the
> input pgc code uses a record struct for returning query results and
> uses an indicator struct that has fewer fields than the record
> struct, the generated .c code will compile with no warning but core
> dump. This situation comes up when a developer adds a field to an
> existing query, adds the field to the record struct and forgets to
> add the field to the indicator struct.
Thanks for spotting and fixing, committed.
> The attached sample files are a simple sample of pgc code that can be
> used to see the difference in before and after generation and the
> before and after generated code.
Next time it would be nice if the test case was self-contained. Wasn't
that difficult to figure out the table layout, though. :)
> If accepted, this bug fix can be back ported to earlier versions of
> ecpg as well.
As usual this will be done after a couple of days, if no problems
appear. I'm pretty sure there won't but sticking to my workflow here.
Michael
-- 
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Meskes at (Debian|Postgresql) dot Org
Jabber: michael at xmpp dot meskes dot org
VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL
| From: | "Rader, David" <davidr(at)openscg(dot)com> | 
|---|---|
| To: | Michael Meskes <meskes(at)postgresql(dot)org> | 
| Cc: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: [PATCH] ECPG bug fix in preproc when indicator struct is shorter than record struct | 
| Date: | 2018-01-13 14:27:01 | 
| Message-ID: | CAABt7R4xrXs2QsiMeuH_voWeCqmr2KVPZHYrP78YgjbtUY0tpA@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Lists: | pgsql-hackers | 
Thank you!
On Sat, Jan 13, 2018 at 9:02 AM, Michael Meskes <meskes(at)postgresql(dot)org>
wrote:
> > Attached is a proposed patch to fix a bug in the ECPG preprocessor
> > that generates application code that core dumps at run-time. When the
> > input pgc code uses a record struct for returning query results and
> > uses an indicator struct that has fewer fields than the record
> > struct, the generated .c code will compile with no warning but core
> > dump. This situation comes up when a developer adds a field to an
> > existing query, adds the field to the record struct and forgets to
> > add the field to the indicator struct.
>
> Thanks for spotting and fixing, committed.
>
> > The attached sample files are a simple sample of pgc code that can be
> > used to see the difference in before and after generation and the
> > before and after generated code.
>
> Next time it would be nice if the test case was self-contained. Wasn't
> that difficult to figure out the table layout, though. :)
Got it - will add next time.
>
> > If accepted, this bug fix can be back ported to earlier versions of
> > ecpg as well.
>
> As usual this will be done after a couple of days, if no problems
> appear. I'm pretty sure there won't but sticking to my workflow here.
>
Do you want patches for the back ports as well?
I noticed that between 9.6 (which is what we're using with this customer)
and 10 the variable arrsiz was renamed to arrsize, so slight differences.
Did not check earlier releases yet.
> Michael
> --
> Michael Meskes
> Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
> Meskes at (Debian|Postgresql) dot Org
> Jabber: michael at xmpp dot meskes dot org
> VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL
>
| From: | Michael Meskes <meskes(at)postgresql(dot)org> | 
|---|---|
| To: | "Rader, David" <davidr(at)openscg(dot)com> | 
| Cc: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: [PATCH] ECPG bug fix in preproc when indicator struct is shorter than record struct | 
| Date: | 2018-01-13 20:17:45 | 
| Message-ID: | [email protected] | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Lists: | pgsql-hackers | 
> Do you want patches for the back ports as well?
> I noticed that between 9.6 (which is what we're using with this
> customer) and 10 the variable arrsiz was renamed to arrsize, so
> slight differences. Did not check earlier releases yet.
Na, don't worry, git cherry-pick and conflict resolution will do the
trick. But thanks for the heads-up.
Michael
-- 
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Meskes at (Debian|Postgresql) dot Org
Jabber: michael at xmpp dot meskes dot org
VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL