postgresql/src/interfaces/ecpg/test
Tom Lane 6f0cef9353 Fix assorted bugs in ecpg's macro mechanism.
The code associated with EXEC SQL DEFINE was unreadable and full of
bugs, notably:

* It'd attempt to free a non-malloced string if the ecpg program
tries to redefine a macro that was defined on the command line.

* Possible memory stomp if user writes "-D=foo".

* Undef'ing or redefining a macro defined on the command line would
change the state visible to the next file, when multiple files are
specified on the command line.  (While possibly that could have been
an intentional choice, the code clearly intends to revert to the
original macro state; it's just failing to consider this interaction.)

* Missing "break" in defining a new macro meant that redefinition
of an existing name would cause an extra entry to be added to the
definition list.  While not immediately harmful, a subsequent undef
would result in the prior entry becoming visible again.

* The interactions with input buffering are subtle and were entirely
undocumented.

It's not that surprising that we hadn't noticed these bugs,
because there was no test coverage at all of either the -D
command line switch or multiple input files.  This patch adds
such coverage (in a rather hacky way I guess).

In addition to the code bugs, the user documentation was confused
about whether the -D switch defines a C macro or an ecpg one, and
it failed to mention that you can write "-Dsymbol=value".

These problems are old, so back-patch to all supported branches.

Discussion: https://postgr.es/m/998011.1713217712@sss.pgh.pa.us
2024-04-16 12:31:42 -04:00
..
compat_informix ecpg: Fix zero-termination of string generated by intoasc() 2024-02-19 11:38:18 +09:00
compat_oracle Update copyright for 2024 2024-01-03 20:49:05 -05:00
connect Update copyright for 2024 2024-01-03 20:49:05 -05:00
expected Fix assorted bugs in ecpg's macro mechanism. 2024-04-16 12:31:42 -04:00
performance Remove unnecessary parentheses in return statements 2017-09-05 14:52:55 -04:00
pgtypeslib Update copyright for 2024 2024-01-03 20:49:05 -05:00
preproc Update copyright for 2024 2024-01-03 20:49:05 -05:00
sql Fix assorted bugs in ecpg's macro mechanism. 2024-04-16 12:31:42 -04:00
thread Update copyright for 2024 2024-01-03 20:49:05 -05:00
.gitignore Still more .gitignore cleanup. 2010-09-24 13:48:15 -04:00
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.regress Ensure link commands list *.o files before LDFLAGS. 2019-01-02 13:57:54 -05:00
ecpg_schedule Add basic JSON_TABLE() functionality 2024-04-04 20:20:15 +09:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_regress_ecpg.c Make the order of the header file includes consistent 2024-03-13 15:07:00 +01:00
printf_hack.h Un-break ecpg tests for Windows. 2019-06-02 11:07:54 -04:00
regression.h Initial pgindent run with pg_bsd_indent version 2.0. 2017-06-21 14:39:04 -04:00