Skip to content

Commit a6bb6f4

Browse files
committed
fix(BASH_COMPLETION_USER_FILE): explicitly check if it is not /dev/null
Users often set `BASH_COMPLETION_USER_FILE=/dev/null' to explicitly express that there is no user configuration file. However, in broken systems, /dev/null may be a regular file that contains random outputs from arbitary commands whose outputs are discarded. We shall explicitly confirm that the path is not `/dev/null' before sourcing because we do not want to source this unexpected `/dev/null' file. In fact, this caused a problem in the CI testing on GitHub [1] where the command history is output to `HISTFILE=/dev/null'. Here, `/dev/null' gets the history entry `source bash_completion' and then sourced from `bash_completion' itself, which results in an infinite source chain of `bash_completion' -> `/dev/null' -> `bash_completion' -> `/dev/null' -> ... while invoking random commands from the command history. [1] scop#529
1 parent cd39105 commit a6bb6f4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bash_completion

+5-1
Original file line numberDiff line numberDiff line change
@@ -2369,8 +2369,12 @@ fi
23692369
unset compat_dir i _blacklist_glob
23702370
23712371
# source user completion file
2372+
#
2373+
# Remark: We explicitly check that $user_completion is not '/dev/null' since
2374+
# /dev/null may be a regular file in broken systems and can contain arbitrary
2375+
# garbages of suppressed command outputs.
23722376
user_completion=${BASH_COMPLETION_USER_FILE:-~/.bash_completion}
2373-
[[ ${BASH_SOURCE[0]} != "$user_completion" && -r $user_completion && -f $user_completion ]] &&
2377+
[[ $user_completion != "${BASH_SOURCE[0]}" && $user_completion != /dev/null && -r $user_completion && -f $user_completion ]] &&
23742378
. $user_completion
23752379
unset user_completion
23762380

0 commit comments

Comments
 (0)