[PATCH 0/1] tools/bash-completion: fix variable leaks of "IFS" and "word"

Koichi Murase myoga.murase at gmail.com
Sun Nov 14 06:06:39 UTC 2021


Description:

  The bash-completion function for virsh, which is defined in
  /usr/share/bash-completion/completions/virsh (generated from libvirt
  tools/bash-completion/vsh.in), overwrites the shell variables "IFS"
  and "word" on query for completions.

Repeat-By:

  I am testing it with Fedora 35 Workstation where the completion
  script is provided by the package:

    libvirt-client-7.6.0-3.fc35.x86_64

  With a Bash session with bash-completion loaded, one can observe the
  change of Bash behavior after the attempt of the completion for
  "virsh" command as follows:

    $ declare -p IFS | cat -A
    declare -- IFS=" ^I$
    "$
    $ virsh a[TAB][TAB]
    allocpages    attach-device    attach-disk    attach-interface    autostart
    $ virsh a[C-c]
    $ declare -p IFS | cat -A
    declare -- IFS="$
    "$

  Originally the value of IFS is IFS=$' \t\n', but it becomes
  IFS=$'\n' after the attempt of the completion.  After that, word
  splitting of the shell will not be processed as normal:

    $ a='a b c'
    $ printf '<%s>\n' $a
    <a>
    <b>
    <c>
    $ virsh a[TAB][TAB][C-c]
    $ printf '<%s>\n' $a
    <a b c>

  The shell variable "word" is also affected by the virsh completion.

Fix:

  The completion function "_virsh_complete" should declare "IFS" and
  "word" as local variables before changing them.

Reference:

  I initially received the related issue in my project at

    https://github.com/akinomyoga/ble.sh/issues/147

--
Koichi


Koichi Murase (1):
  bash-completion: fix variable leaks of "IFS" and "word"

 tools/bash-completion/vsh.in | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.21.3




More information about the libvir-list mailing list