Protect various compgen invocations from -* leakage (Debian: #766163)

master
Ville Skyttä 2014-11-01 21:44:10 +02:00
parent 4038c71357
commit 882649b712
8 changed files with 18 additions and 12 deletions

View File

@ -952,7 +952,7 @@ _tilde()
local result=0
if [[ $1 == \~* && $1 != */* ]]; then
# Try generate ~username completions
COMPREPLY=( $( compgen -P '~' -u "${1#\~}" ) )
COMPREPLY=( $( compgen -P '~' -u -- "${1#\~}" ) )
result=${#COMPREPLY[@]}
# 2>/dev/null for direct invocation, e.g. in the _tilde unit test
[[ $result -gt 0 ]] && compopt -o filenames 2>/dev/null
@ -1019,7 +1019,7 @@ _expand()
eval cur=$cur 2>/dev/null
elif [[ "$cur" == \~* ]]; then
cur=${cur#\~}
COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
COMPREPLY=( $( compgen -P '~' -u -- "$cur" ) )
[[ ${#COMPREPLY[@]} -eq 1 ]] && eval COMPREPLY[0]=${COMPREPLY[0]}
return ${#COMPREPLY[@]}
fi
@ -1620,7 +1620,7 @@ _cd()
for i in ${CDPATH//:/$'\n'}; do
# create an array of matched subdirs
k="${#COMPREPLY[@]}"
for j in $( compgen -d $i/$cur ); do
for j in $( compgen -d -- $i/$cur ); do
if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
j+="/"
fi

View File

@ -26,19 +26,19 @@ _getent()
case $db in
passwd)
COMPREPLY=( $( compgen -u "$cur" ) )
COMPREPLY=( $( compgen -u -- "$cur" ) )
return 0
;;
group)
COMPREPLY=( $( compgen -g "$cur" ) )
COMPREPLY=( $( compgen -g -- "$cur" ) )
return 0
;;
services)
COMPREPLY=( $( compgen -s "$cur" ) )
COMPREPLY=( $( compgen -s -- "$cur" ) )
return 0
;;
hosts)
COMPREPLY=( $( compgen -A hostname "$cur" ) )
COMPREPLY=( $( compgen -A hostname -- "$cur" ) )
return 0
;;
protocols|networks|ahosts|ahostsv4|ahostsv6|rpc)

View File

@ -86,7 +86,7 @@ _mplayer()
local IFS=$'\n'
for i in ~/.mplayer/skins ${dirs[@]}; do
if [[ -d $i && -r $i ]]; then
for j in $( compgen -d $i/$cur ); do
for j in $( compgen -d -- $i/$cur ); do
COMPREPLY[$k]=${j#$i/}
k=$((++k))
done

View File

@ -11,7 +11,7 @@ _ntpdate()
return 0
;;
-U)
COMPREPLY=( $( compgen -u "$cur" ) )
COMPREPLY=( $( compgen -u -- "$cur" ) )
return 0
;;
-p)

View File

@ -11,7 +11,7 @@ _pkg_delete()
[[ "$prev" == -o || "$prev" == -p || "$prev" == -W ]] && return 0
COMPREPLY=( $( compgen -d "$pkgdir$cur" ) )
COMPREPLY=( $( compgen -d -- "$pkgdir$cur" ) )
COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
return 0

View File

@ -9,7 +9,7 @@ _portupgrade()
local pkgdir=${PKG_DBDIR:-/var/db/pkg}/
COMPREPLY=( $( compgen -d "$pkgdir$cur" ) )
COMPREPLY=( $( compgen -d -- "$pkgdir$cur" ) )
COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
COMPREPLY=( ${COMPREPLY[@]%-*} )

View File

@ -13,7 +13,7 @@ _rcs()
# deal with relative directory
[[ $file == $dir ]] && dir=.
COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) )
COMPREPLY=( $( compgen -f -- "$dir/RCS/$file" ) )
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
file=${COMPREPLY[$i]##*/}

View File

@ -46,6 +46,12 @@ sync_after_int
set test "~part should complete to ~full"
set cmd [format {_tilde "~%s"; printf "%%s\n" "${COMPREPLY[@]}"} $part]
assert_bash_list "~$full" $cmd $test
sync_after_int
# Debian #766163
assert_no_complete "_tilde ~-o"
sync_after_int
teardown