Calling `return' after a funsub outside of a function or `.' context
doesn't behave correctly:
$ bash -c '${ :; }; (return 2); echo $?'
2
$ bash -c '${ :; }; return'
Segmentation fault
From cd67d9defa0dbb7be36c1df163db33e78cac8f27 Mon Sep 17 00:00:00 2001
From: Grisha Levit <[email protected]>
Date: Tue, 28 Nov 2023 00:26:37 -0500
Subject: [PATCH] fix return after funsub
---
subst.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/subst.c b/subst.c
index d235525d..aa7f2f56 100644
--- a/subst.c
+++ b/subst.c
@@ -6857,7 +6857,7 @@ static SHELL_VAR lambdafunc = { ".bash.lambda", 0, 0, 0, 0, 0, 0 };
WORD_DESC *
function_substitute (char *string, int quoted, int flags)
{
- volatile int save_return_catch_flag, function_code;
+ volatile int function_code;
int valsub, stdout_valid, saveout, old_frozen;
int result, pflags, tflag, was_trap;
char *istring, *s;
@@ -6990,11 +6990,9 @@ function_substitute (char *string, int quoted, int flags)
/* if we are in a position to accept return, we have to save the old values */
function_code = 0;
- if (save_return_catch_flag = return_catch_flag)
- {
- unwind_protect_int (return_catch_flag);
- unwind_protect_jmp_buf (return_catch);
- }
+ unwind_protect_int (return_catch_flag);
+ if (return_catch_flag)
+ unwind_protect_jmp_buf (return_catch);
was_trap = running_trap;
--
2.43.0