develooper Front page | perl.perl5.porters | Postings from May 2016

[perl #128171] Assert fail in toke.c postderef code with no othersymptoms: /@0{0*->@/*0

Thread Previous
Dan Collins
May 18, 2016 00:00
[perl #128171] Assert fail in toke.c postderef code with no othersymptoms: /@0{0*->@/*0
Message ID:
# New Ticket Created by  Dan Collins 
# Please include the string:  [perl #128171]
# in the subject line of all future correspondence about this issue. 
# <URL: >

Greetings Porters,

I have compiled bleadperl with the afl-gcc compiler using:

./Configure -Dusedevel -Dprefix='/usr/local/perl-afl' -Dcc='ccache afl-gcc' -Uuselongdouble -Duse64bitall -Doptimize=-g -Uversiononly -Uman1dir -Uman3dir -Dusequadmath -des
AFL_HARDEN=1 make && make test

And then fuzzed the resulting binary using:

AFL_NO_VAR_CHECK=1 afl-fuzz -i in -o out bin/perl @@

After reducing testcases using `afl-tmin` and performing additional minimization by hand, I have located the following testcase that triggers an assert fail in debugging builds of the perl interpreter. The testcase is the 6-character file:


On normal builds, this exits with the expected error. On debug builds, this returns an assert fail.

dcollins@nightshade64:~$ ./perldebug/miniperl -e '/@0{0*->@/*0'
miniperl: toke.c:1935: S_postderef: Assertion `strchr("*[{", next)' failed.
dcollins@nightshade64:~$ ./perl/miniperl -e '/@0{0*->@/*0'
Number found where operator expected at -e line 1, near "*0"
        (Missing operator before 0?)
syntax error at -e line 1, near "*->"
Execution of -e aborted due to compilation errors.

Debugging tool output is below. A bisect was performed, but it appears that this bug has existed since the feature was initally committed (and is only appearing now because "use feature postderef" was a bit too much to expect a fuzzer to stumble on easily).


dcollins@nightshade64:~/perldebug$ gdb --args ./miniperl -e '/@0{0*->@/*0'
GNU gdb (GDB) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./miniperl...done.
(gdb) run
Starting program: /home/dcollins/perldebug/miniperl -e /@0\{0\*-\>@/\*0
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/".
miniperl: toke.c:1935: S_postderef: Assertion `strchr("*[{", next)' failed.

Program received signal SIGABRT, Aborted.
0x00007ffff6cf9478 in raise () from /lib/x86_64-linux-gnu/
(gdb) bt
#0  0x00007ffff6cf9478 in raise () from /lib/x86_64-linux-gnu/
#1  0x00007ffff6cfa8fa in abort () from /lib/x86_64-linux-gnu/
#2  0x00007ffff6cf23a7 in ?? () from /lib/x86_64-linux-gnu/
#3  0x00007ffff6cf2452 in __assert_fail () from /lib/x86_64-linux-gnu/
#4  0x000000000047c77f in S_postderef (funny=42, next=48 '0') at toke.c:1935
#5  0x000000000048f4e1 in Perl_yylex () at toke.c:5373
#6  0x00000000004b9f00 in Perl_yyparse (gramtype=258) at perly.c:332
#7  0x0000000000447469 in S_parse_body (env=0x0, xsinit=0x728923 <xs_init>) at perl.c:2365
#8  0x0000000000445f07 in perl_parse (my_perl=0xa80010, xsinit=0x728923 <xs_init>, argc=3, argv=0x7fffffffe628, env=0x0) at perl.c:1681
#9  0x0000000000728882 in main (argc=3, argv=0x7fffffffe628, env=0x7fffffffe648) at miniperlmain.c:120
(gdb) f 4
#4  0x000000000047c77f in S_postderef (funny=42, next=48 '0') at toke.c:1935
1935        assert(strchr("*[{", next));
(gdb) l
1931    static int
1932    S_postderef(pTHX_ int const funny, char const next)
1933    {
1934        assert(funny == DOLSHARP || strchr("$@%&*", funny));
1935        assert(strchr("*[{", next));
1936        if (next == '*') {
1937            PL_expect = XOPERATOR;
1938            if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
1939                assert('@' == funny || '$' == funny || DOLSHARP == funny);
(gdb) info locals
__PRETTY_FUNCTION__ = "S_postderef"

**PERL -V**

dcollins@nightshade64:~/perl$ ./perl -Ilib -V
Summary of my perl5 (revision 5 version 25 subversion 1) configuration:
  Commit id: 8255316ac82c0fbd7ae49f2f9a217ce063d7bbfb
    osname=linux, osvers=4.5.0-2-amd64, archname=x86_64-linux-ld
    uname='linux nightshade64 4.5.0-2-amd64 #1 smp debian 4.5.3-2 (2016-05-08) x86_64 gnulinux '
    config_args='-Dusedevel -Dprefix=/usr/local/perl-afl -Dcc=ccache afl-gcc -Duselongdouble -Duse64bitall -Doptimize=-g -Uversiononly -Uman1dir -Uman3dir -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=define
    usemymalloc=n, bincompat5005=undef
    cc='ccache afl-gcc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='6.1.0', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='long double', nvsize=16, Off_t='off_t', lseeksize=8
    alignbytes=16, prototype=define
  Linker and Libraries:
    ld='ccache afl-gcc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -g -L/usr/local/lib -fstack-protector-strong'

Characteristics of this binary (from libperl):
                        USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES
                        USE_PERLIO USE_PERL_ATOF
  Built under linux
  Compiled at May 16 2016 07:45:27

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About