postgresql/src/test/regress
Tom Lane 9bc33ef5ec Prevent dangling-pointer access when update trigger returns old tuple.
A before-update row trigger may choose to return the "new" or "old" tuple
unmodified.  ExecBRUpdateTriggers failed to consider the second
possibility, and would proceed to free the "old" tuple even if it was the
one returned, leading to subsequent access to already-deallocated memory.
In debug builds this reliably leads to an "invalid memory alloc request
size" failure; in production builds it might accidentally work, but data
corruption is also possible.

This is a very old bug.  There are probably a couple of reasons it hasn't
been noticed up to now.  It would be more usual to return NULL if one
wanted to suppress the update action; returning "old" is significantly less
efficient since the update will occur anyway.  Also, none of the standard
PLs would ever cause this because they all returned freshly-manufactured
tuples even if they were just copying "old".  But commit 4b93f5799 changed
that for plpgsql, making it possible to see the bug with a plpgsql trigger.
Still, this is certainly legal behavior for a trigger function, so it's
ExecBRUpdateTriggers's fault not plpgsql's.

It seems worth creating a test case that exercises returning "old" directly
with a C-language trigger; testing this through plpgsql seems unreliable
because its behavior might change again.

Report and fix by Rushabh Lathia; regression test case by me.
Back-patch to all supported branches.

Discussion: https://postgr.es/m/CAGPqQf1P4pjiNPrMof=P_16E-DFjt457j+nH2ex3=nBTew7tXw@mail.gmail.com
2018-02-27 13:27:38 -05:00
..
data Fix GIN to support null keys, empty and null items, and full index scans. 2011-01-07 19:16:24 -05:00
expected Prevent dangling-pointer access when update trigger returns old tuple. 2018-02-27 13:27:38 -05:00
input Prevent dangling-pointer access when update trigger returns old tuple. 2018-02-27 13:27:38 -05:00
output Prevent dangling-pointer access when update trigger returns old tuple. 2018-02-27 13:27:38 -05:00
sql Prevent dangling-pointer access when update trigger returns old tuple. 2018-02-27 13:27:38 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
GNUmakefile Fix regression test parallel-make hazard. 2016-08-12 20:51:59 -04:00
Makefile Fix non-GNU makefiles for AIX make. 2017-11-30 00:57:32 -08:00
parallel_schedule Merge large_object.sql test into largeobject.source. 2017-07-17 15:28:17 -04:00
pg_regress.c Honor PGCTLTIMEOUT environment variable for pg_regress' startup wait. 2016-04-20 23:48:13 -04:00
pg_regress.h Update copyrights for 2013 2013-01-01 17:15:01 -05:00
pg_regress_main.c Update copyrights for 2013 2013-01-01 17:15:01 -05:00
README Don't generate plain-text HISTORY and src/test/regress/README anymore. 2014-02-10 20:48:12 -05:00
regress.c Prevent dangling-pointer access when update trigger returns old tuple. 2018-02-27 13:27:38 -05:00
regressplans.sh Tweak regressplans.sh to use any already-set PGOPTIONS. 2000-12-18 02:45:47 +00:00
resultmap Enable compiling with the mingw-w64 32 bit compiler. 2011-12-10 15:35:41 -05:00
serial_schedule Merge large_object.sql test into largeobject.source. 2017-07-17 15:28:17 -04:00
standby_schedule Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00

Documentation concerning how to run these regression tests and interpret
the results can be found in the PostgreSQL manual, in the chapter
"Regression Tests".