Thread
Commits
-
Fix null-pointer crash in ECPG compiler.
- 917fdbc633e2 18 (unreleased) landed
- 7f5e0b22e5ea 19 (unreleased) landed
-
ecpg: fix some memory leakage of data-type-related structures.
- 0e6060790d65 18.0 cited
-
[BUG] ECPG crash with union type
Jehan-Guillaume de Rorthais <jgdr@dalibo.com> — 2026-06-25T09:48:49Z
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, -
Re: [BUG] ECPG crash with union type
Tom Lane <tgl@sss.pgh.pa.us> — 2026-06-25T20:46:05Z
Jehan-Guillaume de Rorthais <jgdr@dalibo.com> writes: > 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. > ... > 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; Yeah, I agree. Will fix, thanks for the report! regards, tom lane
-
Re: [BUG] ECPG crash with union type
Jehan-Guillaume de Rorthais <jgdr@dalibo.com> — 2026-06-26T10:00:52Z
On Thu, 25 Jun 2026 16:46:05 -0400 Tom Lane <tgl@sss.pgh.pa.us> wrote: >>[…] > Yeah, I agree. Will fix, thanks for the report! Thank you for your quick answer and commit! Have a good day,