postgresql/src/interfaces/ecpg/test/sql
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
..
.gitignore Further cleanup for recent JSON-related commits. 2024-04-04 13:21:25 -04:00
Makefile Fix assorted bugs in ecpg's macro mechanism. 2024-04-16 12:31:42 -04:00
array.pgc Fix format truncation issue from ECPG test 2019-08-02 09:51:12 +09:00
binary.pgc Make some ecpg test cases more robust against unexpected errors that happen 2019-01-30 10:39:32 +01:00
bytea.pgc Fix ecpg crash with bytea and cursor variables. 2020-06-30 18:34:41 +02:00
code100.pgc Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
copystdout.pgc Updated parser file to the one generated by the latest version of parse.[awk|pl] from the latest version of gram.y 2008-11-13 11:54:39 +00:00
createtableas.pgc Sync ECPG's CREATE TABLE AS statement with backend's. 2019-02-18 11:57:34 +01:00
declare.pgc Improved ECPG warning as suggested by Michael Paquier and removed test case 2021-08-17 15:01:09 +02:00
define.pgc Fix assorted bugs in ecpg's macro mechanism. 2024-04-16 12:31:42 -04:00
define_prelim.pgc Fix assorted bugs in ecpg's macro mechanism. 2024-04-16 12:31:42 -04:00
desc.pgc Always use the same way to addres a descriptor in ecpg's regression tests. 2014-01-13 10:41:53 +01:00
describe.pgc Remove unnecessary parentheses in return statements 2017-09-05 14:52:55 -04:00
dynalloc.pgc Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
dynalloc2.pgc Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
dyntest.pgc Avoid premature de-doubling of quote marks in ECPG strings. 2020-10-22 18:29:46 -04:00
execute.pgc Add documentation and tests for quote marks in ECPG literal queries. 2020-10-22 18:29:46 -04:00
fetch.pgc Make some ecpg test cases more robust against unexpected errors that happen 2019-01-30 10:39:32 +01:00
func.pgc More variables gcc moans about 2009-05-20 16:39:56 +00:00
indicators.pgc More variables gcc moans about 2009-05-20 16:39:56 +00:00
insupd.pgc Fix whitespace issues found by git diff --check, add gitattributes 2013-11-10 14:48:29 -05:00
meson.build Fix assorted bugs in ecpg's macro mechanism. 2024-04-16 12:31:42 -04:00
oldexec.pgc Remove unnecessary parentheses in return statements 2017-09-05 14:52:55 -04:00
parser.pgc Fix whitespace issues found by git diff --check, add gitattributes 2013-11-10 14:48:29 -05:00
prepareas.pgc Implement PREPARE AS statement for ECPG. 2019-05-22 04:58:29 +02:00
quote.pgc Make some ecpg test cases more robust against unexpected errors that happen 2019-01-30 10:39:32 +01:00
show.pgc More variables gcc moans about 2009-05-20 16:39:56 +00:00
sqlda.pgc Remove HAVE_LONG_LONG_INT 2019-11-07 13:30:04 +01:00
sqljson.pgc Add more SQL/JSON constructor functions 2023-07-26 17:08:33 +09:00
sqljson_jsontable.pgc JSON_TABLE: Add support for NESTED paths and columns 2024-04-08 16:14:13 +09:00
twophase.pgc Remove unnecessary parentheses in return statements 2017-09-05 14:52:55 -04:00