]> granicus.if.org Git - postgresql/commit
Fix an ancient logic error in plpgsql's exec_stmt_block: it thought it could
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Feb 2007 18:38:08 +0000 (18:38 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Feb 2007 18:38:08 +0000 (18:38 +0000)
commit36149aac15a3423e0bd10f106d4267b592194f81
tree5f7817d8a0f4dd6e66af696cb2d29b4971942266
parent3e94cf51d7f930e3fec09836d2b488189889a441
Fix an ancient logic error in plpgsql's exec_stmt_block: it thought it could
get away with not (re)initializing a local variable if the variable is marked
"isconst" and not "isnull".  Unfortunately it makes this decision after having
already freed the old value, meaning that something like

   for i in 1..10 loop
     declare c constant text := 'hi there';

leads to subsequent accesses to freed memory, and hence probably crashes.
(In particular, this is why Asif Ali Rehman's bug leads to crash and not
just an unexpectedly-NULL value for SQLERRM: SQLERRM is marked CONSTANT
and so triggers this error.)

The whole thing seems wrong on its face anyway: CONSTANT means that you can't
change the variable inside the block, not that the initializer expression is
guaranteed not to change value across successive block entries.  Hence,
remove the "optimization" instead of trying to fix it.
src/pl/plpgsql/src/pl_exec.c