postgres.git / summary / log / commit / refs
commit a460f7eb3d5ab269fa72f0b4350e561ec158b0e7
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon Sep 13 16:42:04 2021 +0000
First released in: 15.0, 9.6.24, 10.19, 11.14, 12.9, 13.5, 14.0
Fix EXIT out of outermost block in plpgsql.
Ordinarily, using EXIT this way would draw "control reached end of
function without RETURN". However, if the function is one where we
don't require an explicit RETURN (such as a DO block), that should
not happen. It did anyway, because add_dummy_return() neglected to
account for the case.
Per report from Herwig Goemans. Back-patch to all supported branches.
Discussion: https://postgr.es/m/868ae948-e3ca-c7ec-95a6-83cfc08ef750@gmail.com
src/pl/plpgsql/src/pl_comp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c
index 75249b3ec8e..e88c1ac551e 100644
--- a/src/pl/plpgsql/src/pl_comp.c
+++ b/src/pl/plpgsql/src/pl_comp.c
@@ -976,9 +976,11 @@ add_dummy_return(PLpgSQL_function *function)
/*
* If the outer block has an EXCEPTION clause, we need to make a new outer
* block, since the added RETURN shouldn't act like it is inside the
- * EXCEPTION clause.
+ * EXCEPTION clause. Likewise, if it has a label, wrap it in a new outer
+ * block so that EXIT doesn't skip the RETURN.
*/
- if (function->action->exceptions != NULL)
+ if (function->action->exceptions != NULL ||
+ function->action->label != NULL)
{
PLpgSQL_stmt_block *new;
[parent: 3768c468df58]