• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revisão4222 (tree)
Hora2022-11-23 14:20:47
Autormagicant

Mensagem de Log

Disallow recursive xtrace (#46095)

Mudança Sumário

Diff

--- yash/trunk/NEWS (revision 4221)
+++ yash/trunk/NEWS (revision 4222)
@@ -23,6 +23,8 @@
2323 = The "array" built-in is now completely ignored in the POSIXly-
2424 correct mode. The built-in, formerly a regular built-in, is now
2525 categorized as an "extension" built-in.
26+ = The xtrace option is now ignored while expanding the $PS4
27+ variable to prevent possible infinite recursion.
2628 * The allexport option was wrongly ignored in many assignment
2729 contexts.
2830 * The errexit and errreturn options now work for assignment error
--- yash/trunk/exec.c (revision 4221)
+++ yash/trunk/exec.c (revision 4222)
@@ -822,10 +822,12 @@
822822 /* Prints a trace if the "xtrace" option is on. */
823823 void print_xtrace(void *const *argv)
824824 {
825+ static bool expanding_ps4 = false;
826+
825827 bool tracevars = xtrace_buffer.contents != NULL
826828 && xtrace_buffer.length > 0;
827829
828- if (shopt_xtrace
830+ if (shopt_xtrace && !expanding_ps4
829831 && (!is_executing_auxiliary || shopt_traceall)
830832 && (tracevars || argv != NULL)
831833 #if YASH_ENABLE_LINEEDIT
@@ -834,7 +836,12 @@
834836 ) {
835837 bool first = true;
836838
839+ // Disallow recursion in case $PS4 contains a command substitution
840+ // that may trigger another xtrace, which would be an infinite loop
841+ expanding_ps4 = true;
837842 struct promptset_T prompt = get_prompt(4);
843+ expanding_ps4 = false;
844+
838845 print_prompt(prompt.main);
839846 print_prompt(prompt.styler);
840847
Show on old repository browser