Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 593080 - sys-libs/readline crash in rl_redisplay()
Summary: sys-libs/readline crash in rl_redisplay()
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-07 19:00 UTC by Mateusz Lenik
Modified: 2017-01-16 10:59 UTC (History)
1 user (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 Mateusz Lenik 2016-09-07 19:00:17 UTC
I discovered the problem when trying to load gdb plugin called GEF and then minimized it into the following crashing example:

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>

#include <readline/readline.h>

int main() {
    char *line;

    // simulate GDB "set height 0" and "set width 0" commands
    rl_set_screen_size(INT_MAX, INT_MAX);

    while (1) {
        // '\001' and '\002' bytes seem to cause the crash
        line = readline("\001\033[1;32m\002>\001\033[0m\002");
        if (!line) break;
        puts(line);
    }

    return 0;
}

Output when inspecting the crash site from gdb:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bb93a0 in rl_redisplay () at /usr/src/debug/sys-libs/readline-6.3_p8-r2/readline-6.3/display.c:1235
1235		line[t - 1] = '>';
(gdb) list
1230		 the whole line, indicate that with a special character at the
1231		 right edge of the screen.  If LMARGIN is 0, we need to take the
1232		 wrap offset into account. */
1233	      t = lmargin + M_OFFSET (lmargin, wrap_offset) + _rl_screenwidth;
1234	      if (t < out)
1235		line[t - 1] = '>';
1236	
1237	      if (rl_display_fixed == 0 || forced_display || lmargin != last_lmargin)
1238		{
1239		  forced_display = 0;
(gdb) p wrap_offset
$1 = 11
(gdb) p _rl_screenwidth
$2 = 2147483646
(gdb) p t
$3 = -2147483639
(gdb) p _rl_screenwidth + wrap_offset == t
$4 = 1

Looks like the issue is the integer overflow on line 1233.

Mandatory emerge --info follows:
$ emerge --info readline
Portage 2.3.0 (python 2.7.12-final-0, default/linux/amd64/13.0/systemd, gcc-5.4.0, glibc-2.23-r2, 4.7.2-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-4.7.2-gentoo-x86_64-Intel-R-_Core-TM-_i7-6600U_CPU_@_2.60GHz-with-gentoo-2.3
KiB Mem:    16333496 total,   2609100 free
KiB Swap:   33554428 total,  33331416 free
Timestamp of repository gentoo: Tue, 06 Sep 2016 17:30:01 +0000
sh bash 4.3_p46
ld GNU ld (Gentoo 2.26.1 p1.0) 2.26.1
app-shells/bash:          4.3_p46::gentoo
dev-java/java-config:     2.2.0-r3::gentoo
dev-lang/perl:            5.24.0-r1::gentoo
dev-lang/python:          2.7.12::gentoo, 3.4.5::gentoo
dev-util/cmake:           3.6.1-r1::gentoo
dev-util/pkgconfig:       0.29.1::gentoo
sys-apps/baselayout:      2.3::gentoo
sys-apps/sandbox:         2.10-r2::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69-r2::gentoo
sys-devel/automake:       1.12.6-r1::gentoo, 1.13.4-r1::gentoo, 1.14.1-r1::gentoo, 1.15-r2::gentoo
sys-devel/binutils:       2.26.1::gentoo
sys-devel/gcc:            5.4.0::gentoo
sys-devel/gcc-config:     1.8-r1::gentoo
sys-devel/libtool:        2.4.6-r2::gentoo
sys-devel/make:           4.2.1::gentoo
sys-kernel/linux-headers: 4.7::gentoo (virtual/os-headers)
sys-libs/glibc:           2.23-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

local-crossdev
    location: /usr/local/portage-crossdev
    masters: gentoo
    priority: 10

mlen
    location: /var/lib/layman/mlen
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=broadwell -mclflushopt -mxsavec -mxsaves -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /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=broadwell -mclflushopt -mxsavec -mxsaves -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs cgroup config-protect-if-modified distlocks ebuild-locks fail-clean fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j5 -l5"
PKGDIR="/usr/portage/packages"
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 --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X X509 aac aacplus acl alsa amd64 audit berkdb bzip2 caps cgroups cli cracklib crypt cryptsetup cups cxx dbus dri dri3 faac flac fortran gdbm geoclue geoloc geolocation gif gnome-keyring gtk gtk3 gtkstyle hidpi hotwording iconv idn infinality introspection iproute2 ipv6 jpeg kerberos libedit libnotify llvm lvm mbim mmx mmxext modemmanager modules mp3 mpeg multilib ncurses networkmanager nls nptl ogg opengl openmp opus oss pam pch pcre png policykit profile pulseaudio python qt5 readline samba seccomp session sound sse sse2 ssl startup-notification systemd tcpd theora tiff truetype udev udisks unicode unwind vaapi vim-syntax virt-network vorbis webp widgets x264 xattr xft xinerama 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="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id 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" CPU_FLAGS_X86="aes avx avx2 fma3 mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" 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" INPUT_DEVICES="synaptics evdev" KERNEL="linux" L10N="en" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-6" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" QEMU_SOFTMMU_TARGETS="x86_64 i386 arm" QEMU_USER_TARGETS="x86_64 i386 arm" RUBY_TARGETS="ruby23 ruby21" USERLAND="GNU" VIDEO_CARDS="intel i965" 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:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON

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

sys-libs/readline-6.3_p8-r2::gentoo was built with the following:
USE="-static-libs -utils" ABI_X86="64 -32 -x32"
CFLAGS="-march=broadwell -mclflushopt -mxsavec -mxsaves -O2 -pipe -ggdb"
CXXFLAGS="-march=broadwell -mclflushopt -mxsavec -mxsaves -O2 -pipe -ggdb"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -L."
Comment 1 Mateusz Lenik 2016-09-07 20:03:39 UTC
It seems to be caused by ncurses, when I copied libncurses.so to other distro (where the example was working), it started crashing in exactly the same way.
Comment 2 Mateusz Lenik 2016-09-08 05:53:38 UTC
emerge --info for ncurses

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

sys-libs/ncurses-6.0-r1::gentoo was built with the following:
USE="cxx profile unicode -ada -debug -doc -gpm -minimal -static-libs -test -threads -tinfo -trace" ABI_X86="64 -32 -x32
Comment 3 Mateusz Lenik 2016-11-10 10:02:29 UTC
Turns out it's not ncurses fault. I was able to debug it further and found out that commenting out 'set horizontal-scroll-mode on' line “fixed” it.

I'll have to take a look at other distros again to figure out whether only gentoo is affected or this should go straight to readline maintainers.
Comment 4 SpanKY gentoo-dev 2016-11-10 20:26:33 UTC
you should give 7.0 a test first too
Comment 5 Mateusz Lenik 2016-11-10 20:27:36 UTC
I already did, it is also affected by this bug
Comment 6 SpanKY gentoo-dev 2016-11-10 21:53:15 UTC
then it's most likely a bug in readline and nothing specific to Gentoo.  you can send a report to upstream using bug-readline@gnu.org.
Comment 7 Mateusz Lenik 2017-01-16 10:59:52 UTC
Reported the issue to upstream some time ago, this is not a gentoo bug