postgresql/src
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
..
backend Fix nbtree "deduce NOT NULL" scan key comment. 2024-04-16 12:04:20 -04:00
bin psql: Make output of \dD more stable 2024-04-15 09:28:48 +02:00
common Assorted minor cleanups in the test_json_parser module 2024-04-12 10:32:30 -04:00
fe_utils Allow dbname to be written as part of connstring via pg_basebackup's -R option. 2024-03-21 10:50:33 +05:30
include Fix nbtree posting list comment. 2024-04-16 11:20:41 -04:00
interfaces Fix assorted bugs in ecpg's macro mechanism. 2024-04-16 12:31:42 -04:00
makefiles Optimize pg_popcount() with AVX-512 instructions. 2024-04-06 21:56:23 -05:00
pl Fix plpgsql's handling of -- comments following expressions. 2024-04-10 15:45:58 -04:00
port Optimize visibilitymap_count() with AVX-512 instructions. 2024-04-06 22:58:23 -05:00
template Remove AIX support 2024-02-28 15:17:23 +04:00
test Improve test coverage in bump.c 2024-04-16 16:21:31 +12:00
timezone Update time zone data files to tzdata release 2024a. 2024-02-01 15:57:53 -05:00
tools Undo incorrect typedefs.list change. 2024-04-16 11:38:04 -04:00
tutorial Update copyright for 2024 2024-01-03 20:49:05 -05:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Optimize pg_popcount() with AVX-512 instructions. 2024-04-06 21:56:23 -05:00
Makefile.shlib Remove AIX support 2024-02-28 15:17:23 +04:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
nls-global.mk Remove distprep 2023-11-06 15:18:04 +01:00