Skip to content

Commit 850de53

Browse files
authored
Remove saving prior trap in PROMPT_COMMAND with subshell (#60)
- This was causing crashes in cases where users were doing: export PROMPT_COMMAND="history -a; $PROMPT_COMMAND;" - Original description from contributor: $(trap -p DEBUG)" is launching a sub-shell, bash itself. So when people do "export PROMPT_COMMAND="history -a; $PROMPT_COMMAND;"", they export form the parent shell to subsequent sub-shells. And that creates the infinite loop, that eventually segfault bash.
1 parent ed519db commit 850de53

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bash-preexec.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,15 @@ __bp_install_after_session_init() {
277277
precmd_functions+=(__bp_original_prompt_command)
278278
fi
279279

280+
# Save anything already defined in our trap
281+
__bp_trap_string="$(trap -p DEBUG)"
282+
280283
# Installation is finalized in PROMPT_COMMAND, which allows us to override the DEBUG
281284
# trap. __bp_install sets PROMPT_COMMAND to its final value, so these are only
282285
# invoked once.
283286
# It's necessary to clear any existing DEBUG trap in order to set it from the install function.
284-
# Using \n as it's the most univer delimiter of bash commands
285-
PROMPT_COMMAND=$'\n__bp_trap_string="$(trap -p DEBUG)"\n trap DEBUG\n __bp_install\n'
287+
# Using \n as it's the most universal delimiter of bash commands
288+
PROMPT_COMMAND=$'\ntrap DEBUG\n__bp_install\n'
286289
}
287290

288291
# Run our install so long as we're not delaying it.

0 commit comments

Comments
 (0)