[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] ASS_NOEVAL for BASHOPTS and SHELLOPTS
From: |
Grisha Levit |
Subject: |
[PATCH] ASS_NOEVAL for BASHOPTS and SHELLOPTS |
Date: |
Wed, 7 Feb 2024 01:43:35 -0500 |
(Prompted by the report from Emanuele Torre in [1])
The value of currently_executing_command is garbage when there is an error
during assignment when popping the variable context:
$ bash -c 'declare -i SHELLOPTS; f() { local -; set -f; }; f' |& cat -v
bash: line 1: M-`^WM-R^N^\{: braceexpand:hashall:interactive-comment...
$ bash-asan -c 'declare -i SHELLOPTS; f() { local -; set -f; }; f'
SUMMARY: AddressSanitizer: heap-use-after-free execute_cmd.c:399 in
executing_line_number
[1]: https://lists.gnu.org/archive/html/bug-bash/2024-01/msg00111.html
I'm not sure that allowing the integer attribute to be changed really makes
sense for readonly variables but, in any case, the following should prevent
the issue here:
diff --git a/builtins/set.def b/builtins/set.def
index e0024a97..05f3f942 100644
--- a/builtins/set.def
+++ b/builtins/set.def
@@ -578,7 +578,7 @@ set_shellopts (void)
exported = v ? exported_p (v) : 0;
/* ASS_FORCE so we don't have to temporarily turn off readonly */
- v = bind_variable ("SHELLOPTS", value, ASS_FORCE);
+ v = bind_variable ("SHELLOPTS", value, ASS_FORCE|ASS_NOEVAL);
/* Turn the read-only attribute back on, and turn off the export attribute
if it was set implicitly by mark_modified_vars and SHELLOPTS was not
diff --git a/builtins/shopt.def b/builtins/shopt.def
index e6c77cc5..95459bbc 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -854,7 +854,7 @@ set_bashopts (void)
exported = v ? exported_p (v) : 0;
/* ASS_FORCE so we don't have to temporarily turn off readonly */
- v = bind_variable ("BASHOPTS", value, ASS_FORCE);
+ v = bind_variable ("BASHOPTS", value, ASS_FORCE|ASS_NOEVAL);
/* Turn the read-only attribute back on, and turn off the export attribute
if it was set implicitly by mark_modified_vars and SHELLOPTS was not
- [PATCH] ASS_NOEVAL for BASHOPTS and SHELLOPTS,
Grisha Levit <=