Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 528064 - app-shells/bash-completion-2.1-r92 - completion on empty prompt in root shell gives error message "-su: words: bad array subscript"
Summary: app-shells/bash-completion-2.1-r92 - completion on empty prompt in root shel...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Michał Górny
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-03 00:48 UTC by Ole Langbehn
Modified: 2015-02-07 23:22 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ole Langbehn 2014-11-03 00:48:54 UTC
I have a basic setup of bash-completion. I have disabled all installed completions. When I use tab-completion on an empty prompt in a root shell, I get the following error:

-su: words: bad array subscript

After getting this error, it messes up my terminal (konsole). When e.g. afterwards, I call some non-returning command (tail -f or patch without input) and then abort with Ctrl-C, I can't see anything I type and pressing the return key does not lead to a new prompt on a new line, but displays the new prompt on the same line. After issuing a "reset" command, the terminal is back to normal.

When I add a premature exit (add "return" as line 1) to /etc/profile.d/bash_completion.sh, the error is gone.

Using a user account which has bash-completion enabled (and also no enabled completions) this issue is not reproducable.

Reproducible: Always

Steps to Reproduce:
1. Install bash-completion
2. Open a root shell
3. perform completion on empty input
Actual Results:  
error message: -su: words: bad array subscript

messed up terminal

Expected Results:  
no error, completion results

Portage 2.2.14 (python 2.7.8-final-0, default/linux/amd64/13.0, gcc-4.8.3, glibc-2.19-r1, 3.16.3-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-3.16.3-gentoo-x86_64-Intel-R-_Core-TM-_i7-4800MQ_CPU_@_2.70GHz-with-gentoo-2.2
KiB Mem:    16408064 total,   5972248 free
KiB Swap:   16653308 total,  15497052 free
Timestamp of tree: Sun, 02 Nov 2014 11:45:01 +0000
ld GNU ld (GNU Binutils) 2.24
app-shells/bash:          4.3_p30
dev-java/java-config:     2.2.0
dev-lang/perl:            5.20.1-r2
dev-lang/python:          2.7.8, 3.3.5-r1, 3.4.2
dev-util/cmake:           3.0.2
dev-util/pkgconfig:       0.28-r2
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.13.2
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.13, 2.69
sys-devel/automake:       1.10.3, 1.11.6, 1.12.6, 1.14.1
sys-devel/binutils:       2.24-r3
sys-devel/gcc:            4.8.3
sys-devel/gcc-config:     1.8
sys-devel/libtool:        2.4.3-r1
sys-devel/make:           4.1-r1
sys-kernel/linux-headers: 3.16 (virtual/os-headers)
sys-libs/glibc:           2.19-r1
Repositories: gentoo asux my_local_overlay
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=core-avx2 -O2 -pipe -ggdb"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt /usr/share/maven-bin-3.1/conf /var/bind /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/games/angband/edit/ /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.6/ext-active/ /etc/php/cgi-php5.6/ext-active/ /etc/php/cli-php5.6/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=core-avx2 -O2 -pipe -ggdb"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--keep-going -j --load-average 12.0 --with-bdeps=y"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs compress-build-logs compressdebug config-protect-if-modified distlocks ebuild-locks fail-clean fixlafiles merge-sync news parallel-fetch parallel-install preserve-libs protect-owned sandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://mirror.netcologne.de/gentoo/"
LANG="de_DE.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j9"
PKGDIR="/usr/portage/packages"
PORTAGE_COMPRESS="gzip"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/var/lib/layman/asux /usr/local/portage"
SYNC="rsync://rsync.de.gentoo.org/gentoo-portage"
USE="X Xaw3d a52 aac aalib acl acpi alsa amd64 apache2 audiofile bash-completion berkdb bluetooth branding bsf bzip2 cairo caps cdda cddb cdparanoia cdr cli consolekit cracklib crypt css cups curl cvs cxx dbus dga directfb djvu dri dts dv dvd dvdr encode exif fbcon ffmpeg firefox flac fontconfig fortran ftp gd gdbm gif gimp glut gnome gnuplot gphoto2 gpm gstreamer gtk gtk3 gtkhtml gzip handbook iconv icq icu idn ieee1394 imagemagick imap imlib innodb ipod ipv6 jabber java java6 javascript jingle jpeg jpeg2k kde latex lcms ldap libnotify lm_sensors lzma lzo mad matroska mhash mime mmx mmxext mng modules mono motif mozilla mp3 mp4 mpeg mplayer multilib musicbrainz mysql mysqli ncurses nls nptl ocaml ocamlopt odbc ofx ogg openexr opengl openmp pam pcmcia pcre pdf pic plasma png policykit posix postgres ppds qt3support qt4 rdesktop readline recode rss ruby samba sasl sdl session sharedmem shorten smp sockets sound spell sqlite sqlite3 sse sse2 ssl startup-notification subversion svg syslog tcl tcpd theora threads tidy tiff truetype udev udisks unicode upower usb vaapi vhosts vim-syntax vnc vorbis wifi wmf wxwidgets x264 xcb xcomposite xft xine xinerama xml xmpp xosd xpm xscreensaver xsl xv xvid zlib zsh-completion" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_core authn_dbd authn_dbm authn_default authn_file authz_core authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_connect proxy_http rewrite setenvif so socache_shmcb speling status unique_id unixd userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="efi-64" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="de" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_3" QEMU_SOFTMMU_TARGETS="i386 x86_64" QEMU_USER_TARGETS="i386 x86_64" RUBY_TARGETS="ruby19 ruby20 ruby21" USERLAND="GNU" VIDEO_CARDS="intel i965 vesa" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON

=================================================================
                        Package Settings
=================================================================

app-shells/bash-completion-2.1-r91 was built with the following:
USE="" ABI_X86="64"
Comment 1 Ole Langbehn 2014-11-03 00:54:34 UTC
And before you ask, I have performed the migration steps from the warn elog message of app-shells/bash-completion-2.1-r91

> For bash-completion autoloader to work, all completions need to
> be installed in /usr/share/bash-completion/completions. You may
> need to rebuild packages that installed completions in the old
> location. You can do this using:
>
> $ find /usr/share/bash-completion -maxdepth 1 -type f '!' -name 'bash_completion' -exec emerge -1v {} +
>
> After the rebuild, you should remove the old setup symlinks:
>
> $ find /etc/bash_completion.d -type l -delete
Comment 2 Ole Langbehn 2014-11-12 09:16:33 UTC
The error is happening with -r92 as well, updated the subject to indicate that.

Through diff debugging I found that removing the complete call from line 1947 in /usr/share/bash-completion/bash_completion solves the issue. But then it gets fuzzy for me. Something inside the _minimal function seems to not define the words array correctly. But I can't figure out if it's directly in _minimal or in a sub-function.
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-11-12 09:31:05 UTC
I'm sorry but I currently can't sacrifice any of my time to try to fix this. If you could figure out what exactly goes wrong, that would be very helpful :).
Comment 4 Ole Langbehn 2014-11-12 12:51:40 UTC
(In reply to Michał Górny from comment #3)
> I'm sorry but I currently can't sacrifice any of my time to try to fix this.
> If you could figure out what exactly goes wrong, that would be very helpful
> :).

Sorry, I don't have any time for this either...just got twins.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-11-12 13:49:59 UTC
(In reply to Ole Langbehn from comment #4)
> (In reply to Michał Górny from comment #3)
> > I'm sorry but I currently can't sacrifice any of my time to try to fix this.
> > If you could figure out what exactly goes wrong, that would be very helpful
> > :).
> 
> Sorry, I don't have any time for this either...just got twins.

Congrats :).
Comment 6 Ole Langbehn 2014-11-13 08:26:14 UTC
Got it...

in line 710 of /usr/share/bash-completion/bash_completion, a check against zero is performed:

[[ $cword -eq 0 ]] && return 1

In case of the issue, $cword is set to -1, so does not return.

In the next line, $cword is used as an index for accessing the words array. Accessing the array at index -1 results in the error.

I tried to change line 710 to

[[ $cword -le 0 ]] && return 1

but with the result of no completions on an empty shell. But the erroneous shell behaviour is gone then.

Can you take over from here?
Comment 7 Peter Volkov (RETIRED) gentoo-dev 2014-12-23 22:33:45 UTC
This was fixed upstream, so I think it's sane to apply patch:
http://anonscm.debian.org/cgit/bash-completion/bash-completion.git/commit/?id=a9c556ccad819869a6a5d932aac0a75a99372f08
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-12-23 22:43:03 UTC
We should probably package a snapshot. The 2.1 release is ancient...
Comment 9 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-12-23 23:53:33 UTC
+*bash-completion-2.1_p20141224 (23 Dec 2014)
+
+  23 Dec 2014; Michał Górny <mgorny@gentoo.org>
+  +bash-completion-2.1_p20141224.ebuild:
+  Package a new snapshot with upstream fix for bug #528064 (and more). Update
+  the Gentoo bundle with new patch, proper eselect module version (bug #530798)
+  and fixed non-existing file ref (bug #532126).

Seems to solve the problem for me.