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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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