Skip to content

Commit 2f564a7

Browse files
akinomyogascop
andcommitted
fix(ebtables,iptables): quote table name
Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
1 parent 5edb278 commit 2f564a7

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

completions/ebtables

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,36 @@ _comp_cmd_ebtables()
88
local table="" chain='s/^Bridge chain: \([^ ,]\{1,\}\).*$/\1/p' \
99
targets='ACCEPT DROP CONTINUE RETURN'
1010

11+
local IFS=$' \t\n' # for ${table:+-t "$table"}
1112
[[ ${words[*]} =~ [[:space:]]-(t|-table=?)[[:space:]]*([^[:space:]]+) ]] &&
12-
table="-t ${BASH_REMATCH[2]}"
13+
table=${BASH_REMATCH[2]}
1314

1415
local noargopts='!(-*|*[AIDPFXLZtj]*)'
1516
# shellcheck disable=SC2254
1617
case $prev in
1718
-${noargopts}[AIDPFXLZ])
18-
COMPREPLY=($(compgen -W '`"$1" $table -L 2>/dev/null | \
19+
COMPREPLY=($(compgen -W '`"$1" ${table:+-t "$table"} -L 2>/dev/null | \
1920
command sed -ne "$chain"`' -- "$cur"))
2021
;;
2122
-${noargopts}t)
2223
COMPREPLY=($(compgen -W 'nat filter broute' -- "$cur"))
2324
;;
2425
-${noargopts}j)
25-
if [[ $table == "-t filter" || ! $table ]]; then
26+
if [[ $table == "filter" || ! $table ]]; then
2627
COMPREPLY=($(compgen -W '$targets
27-
$("$1" $table -L 2>/dev/null | \
28+
$("$1" ${table:+-t "$table"} -L 2>/dev/null | \
2829
command sed -n -e "s/INPUT\|OUTPUT\|FORWARD//" \
2930
-e "$chain")' \
3031
-- "$cur"))
31-
elif [[ $table == "-t nat" ]]; then
32+
elif [[ $table == "nat" ]]; then
3233
COMPREPLY=($(compgen -W '$targets
33-
$("$1" $table -L 2>/dev/null | \
34+
$("$1" -t "$table" -L 2>/dev/null | \
3435
command sed -n -e "s/OUTPUT|PREROUTING|POSTROUTING//" \
3536
-e "$chain")' \
3637
-- "$cur"))
37-
elif [[ $table == "-t broute" ]]; then
38+
elif [[ $table == "broute" ]]; then
3839
COMPREPLY=($(compgen -W 'ACCEPT DROP
39-
$("$1" $table -L 2>/dev/null | \
40+
$("$1" -t "$table" -L 2>/dev/null | \
4041
command sed -n -e "s/BROUTING//" -e "$chain")' \
4142
-- "$cur"))
4243
fi

completions/iptables

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,32 @@ _comp_cmd_iptables()
77

88
local table="" chain='s/^Chain \([^ ]\{1,\}\).*$/\1/p'
99

10+
local IFS=$' \t\n' # for ${table:+-t "$table"}
1011
[[ ${words[*]} =~ [[:space:]]-(t|-table=?)[[:space:]]*([^[:space:]]+) ]] &&
11-
table="-t ${BASH_REMATCH[2]}"
12+
table=${BASH_REMATCH[2]}
1213

1314
case $prev in
1415
-*[AIDRPFXLZ])
15-
COMPREPLY=($(compgen -W '`"$1" $table -nL 2>/dev/null | \
16+
COMPREPLY=($(compgen -W '`"$1" ${table:+-t "$table"} -nL 2>/dev/null | \
1617
command sed -ne "s/^Chain \([^ ]\{1,\}\).*$/\1/p"`' -- "$cur"))
1718
;;
1819
-*t)
1920
COMPREPLY=($(compgen -W 'nat filter mangle' -- "$cur"))
2021
;;
2122
-j)
22-
if [[ $table == "-t filter" || ! $table ]]; then
23+
if [[ $table == "filter" || ! $table ]]; then
2324
COMPREPLY=($(compgen -W 'ACCEPT DROP LOG ULOG REJECT
24-
`"$1" $table -nL 2>/dev/null | command sed -ne "$chain" \
25+
`"$1" ${table:+-t "$table"} -nL 2>/dev/null | command sed -ne "$chain" \
2526
-e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
2627
"$cur"))
27-
elif [[ $table == "-t nat" ]]; then
28+
elif [[ $table == "nat" ]]; then
2829
COMPREPLY=($(compgen -W 'ACCEPT DROP LOG ULOG REJECT MIRROR SNAT
29-
DNAT MASQUERADE `"$1" $table -nL 2>/dev/null | \
30+
DNAT MASQUERADE `"$1" -t "$table" -nL 2>/dev/null | \
3031
command sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \
3132
-- "$cur"))
32-
elif [[ $table == "-t mangle" ]]; then
33+
elif [[ $table == "mangle" ]]; then
3334
COMPREPLY=($(compgen -W 'ACCEPT DROP LOG ULOG REJECT MARK TOS
34-
`"$1" $table -nL 2>/dev/null | command sed -ne "$chain" \
35+
`"$1" -t "$table" -nL 2>/dev/null | command sed -ne "$chain" \
3536
-e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
3637
"$cur"))
3738
fi

0 commit comments

Comments
 (0)