Open mcepl opened 4 days ago
Thanks for the report. Sorry for the delayed reply. I could reproduce the problem in my environment, so I have been testing the behavior locally. This seems to be related to Bash's compgen
's behavior called by the bash-completion
framework. The compgen
builtin turned out to behave differently inside/outside Readline. Since bash-completion
is designed and tested with the behavior of the compgen
builtin inside Readline, it can generate broken results when the programmable completion is called outside Readline (as done in ble.sh).
The following example demonstrates the behavior of the compgen
builtin in a plain Bash (without ble.sh):
$ cat bashrc
mkdir -p ~/tmp1/a:b
touch ~/tmp1/a:b/{a..c}.txt
function _test1 {
COMPREPLY=($(compgen -f -- '\~/tmp1/a\\:b/'))
printf '\e[32;1m<%s>\e[m' "${COMPREPLY[@]}" >/dev/tty
}
complete -F _test1 test1
$ bash --rcfile bashrc
$ _test1[RET]
<~/tmp1/a\:b/a.txt><~/tmp1/a\:b/b.txt><~/tmp1/a\:b/c.txt>$
$ test1 [TAB]<~/tmp1/a\:b/a.txt><~/tmp1/a\:b/b.txt><~/tmp1/a\:b/c.txt>~/tmp1/a\:b/[TAB]<~/tmp1/a:b/a.txt><~/tmp1/a:b/b.txt><~/tmp1/a:b/c.xt>
In the above results, one can observe the following behavior of the compgen
builtin:
_test1
outside Bash's programmable completion, the colons in the result of compgen -f '\~/tmp1/a\\:b/'
are quoted as \:
._test1
calls compgen -f '\~/tmp1/a\\:b/'
for the empty word, the colons are still quoted._test1
calls compgen -f '\~/tmp1/a\\:b/'
for the word ~/tmp/a\:b/
, the colons are somehow not quoted. The bash-completion
framework basically calls compgen
for the current word, so it usually sees the result of the third case. However, when the programmable completion setting of bash-completion
is used by ble.sh, it falls into the first case, where extra escaping of the colons are generated. ble.sh considers that \:
would mean the literal '\:', so it considers \:
would need to be quoted as \\\:
in the command line.
When completing a file in directory which names contains colon character (specifically
~/build/devel\:languages\:python\:Factory/python36/
)ble.sh
tries to quote colon characters, but during the completion process, it does it too much, so the result is~/build/devel\\\:languages\\\:python\\\:Factory/python36/CVE-2024-6232-ReDOS-backtrack-tarfile.patch
, which doesn’t work.See https://asciinema.org/a/JS7xiLCezmNnOhEhcJb0HjZj0 (play it in the full screen)