Re: ECPG cleanup and fix for clang compile-time problem

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: John Naylor <johncnaylorls(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: ECPG cleanup and fix for clang compile-time problem
Date: 2024-10-17 18:00:00
Message-ID: a239aec2-6c79-5fc9-9272-cea41158a360@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello Tom,

16.10.2024 19:26, Tom Lane wrote:
> Alexander Lakhin <exclusion(at)gmail(dot)com> writes:
>> Maybe you would like to fix in passing several (not new) defects, I've
>> found while playing with ecpg under Valgrind:
> Done. After evaluation I concluded that none of these were worth the
> trouble to back-patch, but by all means let's fix such things in HEAD.

Thank you for fixing these defects!

I've spent a day testing ecpg preprocessor and found another couple of
bugs:
1)
EXEC SQL BEGIN DECLARE SECTION;
int i = 1;
EXEC SQL END DECLARE SECTION;

EXEC SQL DECLARE c CURSOR FOR SELECT :i;

{;}
}

EXEC SQL OPEN c;

==1247560==
==1247560== Invalid read of size 4
==1247560==    at 0x121C13: dump_variables (variable.c:462)
==1247560==    by 0x10CF75: output_statement (output.c:157)
==1247560==    by 0x116B6B: base_yyparse (preproc.y:1233)
==1247560==    by 0x10C78F: main (ecpg.c:483)
==1247560==  Address 0x4e39bc0 is 16 bytes inside a block of size 32 free'd
==1247560==    at 0x484B27F: free (vg_replace_malloc.c:872)
==1247560==    by 0x1219AE: remove_variables (variable.c:351)
==1247560==    by 0x11899F: base_yyparse (preproc.y:7853)
==1247560==    by 0x10C78F: main (ecpg.c:483)
==1247560==  Block was alloc'd at
==1247560==    at 0x4848899: malloc (vg_replace_malloc.c:381)
==1247560==    by 0x120703: mm_alloc (util.c:87)
==1247560==    by 0x120C3C: new_variable (variable.c:12)
==1247560==    by 0x11C27C: base_yyparse (preproc.y:8984)
==1247560==    by 0x10C78F: main (ecpg.c:483)
...

---
2)
EXEC SQL BEGIN DECLARE SECTION;
char s[100];
EXEC SQL END DECLARE SECTION;

EXEC SQL DECLARE cur_1 CURSOR FOR SELECT 1;
EXEC SQL FETCH cur_1 INTO :s[0];

==1247848== Invalid read of size 4
==1247848==    at 0x121388: find_variable (variable.c:238)
==1247848==    by 0x11D684: base_yyparse (preproc.y:9751)
==1247848==    by 0x10C78F: main (ecpg.c:483)
==1247848==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

---
Also, processing of .../ecpg/test/sql/include.pgc, containing only:
EXEC SQL INCLUDE ../sql;

emits merely:
input in flex scanner failed

I think that's all that can be found here without extra efforts.

Best regards,
Alexander

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2024-10-17 18:05:02 Re: minor doc issue in 9.16.2.1.1. Boolean Predicate Check Expressions
Previous Message Marcos Pegoraro 2024-10-17 17:47:57 Re: minor doc issue in 9.16.2.1.1. Boolean Predicate Check Expressions