Public bug reported:
Package: ipset
Version: 7.19-1ubuntu3
Release: Ubuntu 26.04
bash: 5.3
bash-completion: 2.16.0-8build1
Steps to reproduce:
1. apt install ipset bash-completion
2. open a new bash shell
3. type "ipset " and press Tab
Expected: list of ipset subcommands
Actual:
-bash: syntax error: unexpected end of file from `{' command on line 167
Root cause:
/usr/share/bash-completion/completions/ipset (from
AllKind/ipset-bash-completion)
lines ~1003-1007 do:
if ! declare -F _ipset_known_hosts &>/dev/null; then
eval '_ipset_known_hosts() { '$(declare -f _known_hosts_real | \
grep -v __ltrim_colon_completions | \
grep -Ev "^_known_hosts_real.*$" | grep -Ev "^(\{|\})")' }'
fi
bash-completion 2.16 removed _known_hosts_real in favour of
_comp_compgen_known_hosts. `declare -f _known_hosts_real` therefore returns
nothing, so eval is given:
_ipset_known_hosts() { }
An empty function body is a syntax error in bash:
$ printf 'f() { }\n' | bash -n
bash: line 1: syntax error near unexpected token `}'
Hence the error every time completion is loaded.
Proposed fix: prefer _comp_compgen_known_hosts when available, keep the old
_known_hosts_real path for older bash-completion, and never eval an empty
body. Also terminate the generated body with a newline instead of a space,
since $(...) strips trailing newlines and a body ending in a simple command
then yields "cmd }".
Patch attached (applies with `patch -p1` in the completions directory).
Verified after patching:
bash -n /usr/share/bash-completion/completions/ipset -> exit 0
ipset <TAB> -> subcommands listed
ipset -r <TAB> -> hostnames listed
Tested against three environments:
- bash-completion 2.16 (_comp_compgen_known_hosts only)
- older bash-completion (_known_hosts_real only)
- neither helper present (fallback to compgen -A hostname)
All three produce hostname completions, no syntax error.
Note: the copy currently in the archive also carries a Debian patch for an
invalid process substitution at line 365
(`done < <(PATH=${PATH}:/sbin ( command ip -o link show ) 2>/dev/null)`),
which is still broken on upstream master.
** Affects: ipset (Ubuntu)
Importance: Undecided
Status: New
** Attachment added: "ipset-fix.patch"
https://bugs.launchpad.net/bugs/2173038/+attachment/6015043/+files/ipset-fix.patch
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2173038
Title:
ipset bash completion: syntax error on Tab with bash-completion 2.16
(_known_hosts_real removed)
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/ipset/+bug/2173038/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs