| From: | Jehan-Guillaume de Rorthais <jgdr(at)dalibo(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Subject: | [BUG] ECPG crash with union type |
| Date: | 2026-06-25 09:48:49 |
| Message-ID: | 20260625114849.34b2148e@karst |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
One of our customer hit a sigsev with ecpg lately. Their team created a simple
scenario and point us the origin of the crash in ECPG code. The credit goes to
them (iMSA) for that work.
Here is their scenario:
EXEC SQL BEGIN DECLARE SECTION;
struct SVA1_BF5L10
{
char NFCTACS[2];
char ESUICRS[1];
union UVA1_BF5L10
{
long pointeur1;
long pointeur2;
} UVA1;
} SVA1;
EXEC SQL END DECLARE SECTION;
Trying to compile it leads to the segfault:
$ ecpg sc1.pgc
Segmentation fault (core dumped)
I have tested their scenario on all supported branches and the crash appears in
v18. We were able to identify commit 0e6060790d6533 (cc Tom Lane as author) as
the origin of the regression. Reverting the commit in a test branch doesn't
expose the crash anymore and sc1.c is generated without errors.
In ecpg code, union's type size is set to NULL in "ecpg/preproc/preproc.y":
else
{
$$.type_enum = ECPGt_union;
$$.type_sizeof = NULL;
}
But the patch change the following code in "ecpg/preproc/type.c" leading to
the segfault in "mm_strdup":
struct ECPGtype *
-ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, …
+ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type,
+ const char *type_name, …
{
struct ECPGtype *ne = ECPGmake_simple_type(type, "1", 0);
ne->type_name = mm_strdup(type_name);
ne->u.members = ECPGstruct_member_dup(rm);
- ne->struct_sizeof = struct_sizeof;
+ ne->struct_sizeof = mm_strdup(struct_sizeof);
If setting "$$.type_sizeof = NULL;" is legit for unions (I didn't try to wrap
my head around this code), maybe this change should be:
- ne->struct_sizeof = struct_sizeof;
+ ne->struct_sizeof = struct_sizeof ? mm_strdup(struct_sizeof):NULL;
Regards,
| From | Date | Subject | |
|---|---|---|---|
| Next Message | vignesh C | 2026-06-25 10:00:20 | Re: Include sequences in publications created by pg_createsubscriber |
| Previous Message | Robert Haas | 2026-06-25 09:43:50 | Re: RFC: Logging plan of the running query |