[Bash-completion-devel] [bash-completion-Bugs][313270] "set -u" crashes bash_completion

bash-completion-bugs at alioth.debian.org bash-completion-bugs at alioth.debian.org
Fri Aug 30 17:55:40 UTC 2013


bash-completion-Bugs item #313270 was changed at 2013-08-30 13:55 by Ian! D. Allen
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=313270&group_id=100114

Status: Open
Priority: 3
Submitted By: Nobody (None)
Assigned to: Nobody (None)
Summary: "set -u" crashes bash_completion 
Distribution: --Distribution-Agnostic--
Originally reported in: None
Milestone: None
Status: None
Original bug number: 


Initial Comment:
Anonymous message posted by pdbj at mac.com

When the shell has "set -u" or "set -o nounset", which cause references to unset variables to error, bash_completion errors in two ways:

1.  On sourcing bash_completion:

$ env -i bash --login --noprofile --norc

bash-3.2$ set -u ; . /sw/etc/bash_completion
bash: BASH_COMPLETION_DEBUG: unbound variable
bash: BASH_COMPLETION: unbound variable
bash: BASH_COMPLETION_DIR: unbound variable
bash: BASH_COMPLETION_COMPAT_DIR: unbound variable
bash: BASH_COMPLETION: unbound variable
bash: list[@]: unbound variable
bash: BASH_COMPLETION_COMPAT_DIR: unbound variable
bash: BASH_COMPLETION_DIR: unbound variable
bash: BASH_COMPLETION: unbound variable

2.  When trying to complete:

bash-3.2$ ls <tab>bash: !ref: unbound variable
bash: !ref: unbound variable
bash: words[i]: unbound variable

This is in

$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.

with bash_completion 1.3.

Patch attached.  Most of the issues are in the bash_completion file itself.  A few files in bash_completion.d/ make reference to undefined variables on the complete line, for example fink:

complete $filenames -F _fink fink

I've removed these variable references, since I can't see that they are set anywhere.  If they are used in some cases, these should be restored as "${filenames:-}", etc.

Thanks,
Peter

----------------------------------------------------------------------

Comment By: Ian! D. Allen (idallen-guest)
Date: 2013-08-30 13:55

Message:
In addition to failures under "set -u", using "shopt -s failglob" also
causes errors that make all bash_completion versions (including 2.1)
unusable:

    $ env -i bash --login --noprofile --norc
    bash-4.2$ shopt -s failglob
    bash-4.2$ . /usr/share/bash-completion/bash_completion 
    bash-4.2$ make <TAB> bash: no match: words[0]=${!ref}${COMP_WORDS[i]}
    bash-4.2$ find <TAB> bash: no match: words[0]=${!ref}${COMP_WORDS[i]}
    bash-4.2$ mutt <TAB> bash: no match: words[0]=${!ref}${COMP_WORDS[i]}
    bash-4.2$ date <TAB> bash: no match: words[0]=${!ref}${COMP_WORDS[i]}
    bash-4.2$ echo <TAB> bash: no match: words[0]=${!ref}${COMP_WORDS[i]}
    etc.

The code has many errors where characters are not quoted (e.g. bash
array subscripts), so they try to expand as GLOB file names and fail.

As an example, to fix the above, change the lines:

    eval $2[$j]=\${!ref}\${COMP_WORDS[i]}

to this:

    eval "$ref"='${!ref-}${COMP_WORDS[i]-}'

everywhere (and also fix it so that "set -u" doesn't also make it fail).


----------------------------------------------------------------------

Comment By: Ville Skyttä  (scop-guest)
Date: 2011-08-06 13:11

Message:
set -u safety is on our roadmap for bash-completion 3.0:
http://wiki.debian.org/Teams/BashCompletion/Proposals/Roadmap

For now I've applied the rpmcheck fix.  Completions for fink, launchctl, and open are not shipped by us so they need to be addressed somewhere else.

For future patches, please create them against the git master branch, and send them formatted with "git format-patch", see instructions in README shipped with bash-completion.

----------------------------------------------------------------------

You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=313270&group_id=100114



More information about the Bash-completion-devel mailing list