[dev] [bug] [9base rc] segfault on sigint in `{read}

From: <pranomestro_AT_gmail.com>
Date: Fri, 09 Dec 2016 19:34:03 +0100

Hey suckless,

I think I found a bug in 9base rc.
To replicate, execute following code:

        #!/usr/bin/env rc
        fn sigint{
                echo in sigint
                exit 1
        }
        l=`{read}

and send sigint to the program (for example
by typing CTRL-C.

The desired output would be 'in sigint', but instead,
by shell tells me this:

        ^C7974: signal: interrupt
        fish: './rcbt' terminated by signal SIGSEGV (Adressbereichsfehler)

When examining the core with gdb, this is the output:

        gdb /usr/local/plan9/bin/rc core.7973
        Reading symbols from /usr/local/plan9/bin/rc...done.
        [New LWP 7973]
        Core was generated by `rc ./rcbt'.
        Program terminated with signal SIGSEGV, Segmentation fault.
        #0 0x0000000000404369 in p9main (argc=2, argv=0x7ffcd7275338) at exec.c:188
        188 (*runq->code[runq->pc-1].f)();

`bt` results this:

        #0 0x0000000000404369 in p9main (argc=2, argv=0x7ffcd7275338) at exec.c:188
        #1 0x0000000000410dd1 in main ()

`info locals` results this:

        Reading symbols from /usr/local/plan9/bin/rc...done.
        [New LWP 7973]
        Core was generated by `rc ./rcbt'.
        Program terminated with signal SIGSEGV, Segmentation fault.
        #0 0x0000000000404369 in p9main (argc=2, argv=0x7ffcd7275338) at exec.c:188
        188 (*runq->code[runq->pc-1].f)();
        bootstrap = {[0] = {
            f = 0x2,
            i = 2,
            s = 0x2 <error: Cannot access memory at address 0x2>
          }, [1] = {
            f = 0x404786 <Xmark>,
            i = 4212614,
            s = 0x404786 <Xmark> "UH\211\345\350(\366\377\377\220]\303UH\211\345\350b\366\377\377\220]\303UH\211\345H\203\354\020H\213\005\243\312-"
          }, [2] = {
            f = 0x404b1f <Xword>,
            i = 4213535,
            s = 0x404b1f <Xword> "UH\211\345H\213\005&\307-"
          }, [3] = {
            f = 0x4ab88e,
            i = 4896910,
            s = 0x4ab88e "*"
          }, [4] = {
            f = 0x405078 <Xassign>,
            i = 4214904,
            s = 0x405078 <Xassign> "UH\211\345H\203\354\020H\213\005\311\301-"
          }, [5] = {
            f = 0x404786 <Xmark>,
            i = 4212614,
            s = 0x404786 <Xmark> "UH\211\345\350(\366\377\377\220]\303UH\211\345\350b\366\377\377\220]\303UH\211\345H\203\354\020H\213\005\243\312-"
          }, [6] = {
            f = 0x404786 <Xmark>,
            i = 4212614,
            s = 0x404786 <Xmark> "UH\211\345\350(\366\377\377\220]\303UH\211\345\350b\366\377\377\220]\303UH\211\345H\203\354\020H\213\005\243\312-"
          }, [7] = {
            f = 0x404b1f <Xword>,
            i = 4213535,
            s = 0x404b1f <Xword> "UH\211\345H\213\005&\307-"
          }, [8] = {
            f = 0x4ab88e,
            i = 4896910,
            s = 0x4ab88e "*"
          }, [9] = {
            f = 0x4051c5 <Xdol>,
            i = 4215237,
            s = 0x4051c5 <Xdol> "UH\211\345H\203\354\060H\213\005|\300-"
          }, [10] = {
            f = 0x404b1f <Xword>,
            i = 4213535,
            s = 0x404b1f <Xword> "UH\211\345H\213\005&\307-"
          }, [11] = {
            f = 0xc69ac0,
            i = 13015744,
            s = 0xc69ac0 "/usr/local/plan9/etc/rcmain"
          }, [12] = {
            f = 0x404b1f <Xword>,
            i = 4213535,
            s = 0x404b1f <Xword> "UH\211\345H\213\005&\307-"
          }, [13] = {
            f = 0x4ab890,
            i = 4896912,
            s = 0x4ab890 "."
          }, [14] = {
            f = 0x40a073 <Xsimple>,
            i = 4235379,
            s = 0x40a073 <Xsimple> "UH\211\345H\203\354\060H\213\005\316q-"
          }, [15] = {
            f = 0x404592 <Xexit>,
            i = 4212114,
            s = 0x404592 <Xexit> "UH\211\345ATSH\203\354\020\350^\346\004"
          }, [16] = {
            f = 0x0,
            i = 0,
            s = 0x0
          }, [17] = {
            f = 0x42bd41 <malloc+81>,
            i = 4373825,
            s = 0x42bd41 <malloc+81> "H\205\300H\211\302\017\204", <incomplete sequence \313>
          }, [18] = {
            f = 0x0,
            i = 0,
            s = 0x0
          }, [19] = {
            f = 0x41ed96 <getenv+22>,
            i = 4320662,
            s = 0x41ed96 <getenv+22> "H\213-\273\003,"
          }, [20] = {
            f = 0x7ffcd72751a0,
            i = -685289056,
            s = 0x7ffcd72751a0 ""
          }, [21] = {
            f = 0x4c4285,
            i = 4997765,
            s = 0x4c4285 ""
          }, [22] = {
            f = 0x7ffcd736f2dc,
            i = -684264740,
            s = 0x7ffcd736f2dc "linux-vdso.so.1"
          }, [23] = {
            f = 0x10,
            i = 16,
            s = 0x10 <error: Cannot access memory at address 0x10>
          }, [24] = {
            f = 0x1,
            i = 1,
            s = 0x1 <error: Cannot access memory at address 0x1>
          }, [25] = {
            f = 0x4007a9 <init_cacheinfo+489>,
            i = 4196265,
            s = 0x4007a9 <init_cacheinfo+489> "H\211Ǹ"
          }, [26] = {
            f = 0x0,
            i = 0,
            s = 0x0
          }, [27] = {
            f = 0x1,
            i = 1,
            s = 0x1 <error: Cannot access memory at address 0x1>
          }, [28] = {
            f = 0x2,
            i = 2,
            s = 0x2 <error: Cannot access memory at address 0x2>
          }, [29] = {
            f = 0x7ffcd7275338,
            i = -685288648,
            s = 0x7ffcd7275338 "$\\'\327\374\177"
          }, [30] = {
            f = 0x7ffcd7275350,
            i = -685288624,
            s = 0x7ffcd7275350 ".\\'\327\374\177"
          }, [31] = {
            f = 0x2,
            i = 2,
            s = 0x2 <error: Cannot access memory at address 0x2>
          }}
        num = "7973\000\000\000\000\063\000\000"
        rcmain = 0xc69ac0 "/usr/local/plan9/etc/rcmain"
        i = 0

I am running arch linux 4.8.12-3 with gcc 6.2.1 and 9base commit de27e3fba5
(which is HEAD). `make -n -f Makefile rc` in 9base/rc results this:

        echo CC code.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 code.c
        echo CC exec.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 exec.c
        echo CC getflags.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 getflags.c
        echo CC glob.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 glob.c
        echo CC here.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 here.c
        echo CC io.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 io.c
        echo CC lex.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 lex.c
        echo CC pcmd.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 pcmd.c
        echo CC pfnc.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 pfnc.c
        echo CC simple.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 simple.c
        echo CC subr.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 subr.c
        echo CC trap.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 trap.c
        echo CC tree.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 tree.c
        echo CC unixcrap.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 unixcrap.c
        echo CC var.c
        cc -c -I. -DPLAN9PORT -DPREFIX="\"/usr/local/plan9\"" -g -I../lib9 -I/usr/local/plan9/include -I../lib9 var.c

That's all information I could gather. I hope this can be reproduced.

Greetings,

pranomostro
Received on Fri Dec 09 2016 - 19:34:03 CET

This archive was generated by hypermail 2.3.0 : Fri Dec 09 2016 - 19:36:12 CET