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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux