Fix use-after-free bug with event triggers in an extension script
authorAlvaro Herrera
Wed, 16 Sep 2020 00:03:14 +0000 (21:03 -0300)
committerAlvaro Herrera
Wed, 16 Sep 2020 00:03:14 +0000 (21:03 -0300)
commitced138e8cbac7f5a840de8679e9882665478c680
tree2e13dac6c8dae77c2a71cc3ed284a2857a0c5bb3
parent10a5b35a0061d9747ac7594c5e6faa0513276593
Fix use-after-free bug with event triggers in an extension script

ALTER TABLE commands in an extension script are added to an event
trigger command list; but starting with commit b5810de3f4 they do so in
a memory context that's too short-lived, so when execution ends and time
comes to use the entries, they've already been freed.

(This would also be a problem with ALTER TABLE commands in a
multi-command query string, but these serendipitously end in
PortalContext -- which probably explains why it took so long for this to
be reported.)

Fix by using the memory context specifically set for that, instead.

Backpatch to 13, where the aforementioned commit appeared.

Reported-by: Philippe Beaudoin
Author: Jehan-Guillaume de Rorthais 
Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost
src/backend/commands/event_trigger.c
src/test/modules/test_extensions/Makefile
src/test/modules/test_extensions/expected/test_extensions.out
src/test/modules/test_extensions/sql/test_extensions.sql
src/test/modules/test_extensions/test_ext_evttrig--1.0--2.0.sql [new file with mode: 0644]
src/test/modules/test_extensions/test_ext_evttrig--1.0.sql [new file with mode: 0644]
src/test/modules/test_extensions/test_ext_evttrig.control [new file with mode: 0644]