I've noticed a couple of segfaults from sort. First one happens when
building ports/textproc/ispell on amd64 (it's ok on i386). It occurs
after printing 'Creating list of legal roots/flags' (but the build
continues so it's not very apparent unless you grep over the port
build logs looking for core dumps).

$ cd /usr/ports/textproc/ispell
$ make
[...]
$ cd `make show=WRKSRC`/languages/american

I've unrolled the Makefile and build script and generated the
intermediate file it's working on so you don't need to mess around
with the port:

$ ftp -o- http://junkpile.org/sort-ispell.txt | sort -u -t/ +0f -1 +0

either way:

$ gdb /usr/bin/sort sort.core

GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd4.6"...
Core was generated by `sort'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/lib/libc.so.53.1...done.
Loaded symbols for /usr/lib/libc.so.53.1
Reading symbols from /usr/libexec/ld.so...done.
Loaded symbols for /usr/libexec/ld.so
#0  0x0000000000402705 in enterfield (tablepos=0x20472a000 <Address 0x20472a000 
out of bounds>, endkey=0x204729ff8 "URGE", cur_fld=0x210399870, gflags=0)
    at /usr/src/usr.bin/sort/fields.c:172
172                                     *tablepos++ = lweight[*start];
(gdb) bt
#0  0x0000000000402705 in enterfield (tablepos=0x20472a000 <Address 0x20472a000 
out of bounds>, endkey=0x204729ff8 "URGE", cur_fld=0x210399870, gflags=0)
    at /usr/src/usr.bin/sort/fields.c:172
#1  0x0000000000402360 in enterkey (keybuf=0x204729fe8, line=0x808bd0, size=23, 
fieldtable=0x210399800) at /usr/src/usr.bin/sort/fields.c:109
#2  0x0000000000403692 in makekey (flno=-1, filelist={top = 8425552, names = 
0x809050}, nfiles=1, buffer=0x204729fe8,
    bufend=0x204729fff "g" <Address 0x20472a000 out of bounds>, 
ftbl=0x210399800) at /usr/src/usr.bin/sort/files.c:228
#3  0x0000000000403d7d in fsort (binno=-1, depth=0, infiles={top = 8425552, 
names = 0x809050}, nfiles=1, outfp=0x203b56300, ftbl=0x210399800)
    at /usr/src/usr.bin/sort/fsort.c:114
#4  0x00000000004070e1 in main (argc=7, argv=0x7f7ffffbfda0) at 
/usr/src/usr.bin/sort/sort.c:304
(gdb) bt full
#0  0x0000000000402705 in enterfield (tablepos=0x20472a000 <Address 0x20472a000 
out of bounds>, endkey=0x204729ff8 "URGE", cur_fld=0x210399870, gflags=0)
    at /usr/src/usr.bin/sort/fields.c:172
        start = (u_char *) 0x202944003 "e/R\ne/S\nn/S\n\n\n/D\n\n\n\n\n"
        end = (u_char *) 0x202944006 "\ne/S\nn/S\n\n\n/D\n\n\n\n\n"
        lineend = (u_char *) 0x202944006 "\ne/S\nn/S\n\n\n/D\n\n\n\n\n"
        mask = (u_char *) 0x80d380 '\001' <repeats 200 times>...
        lweight = (u_char *) 0x80d9a0 ""
        icol = {p = 0x210399c00, num = 1, indent = 0}
        tcol = {p = 0x0, num = 0, indent = 0}
        flags = 0
        Rflag = 0
#1  0x0000000000402360 in enterkey (keybuf=0x204729fe8, line=0x808bd0, size=23, 
fieldtable=0x210399800) at /usr/src/usr.bin/sort/fields.c:109
        i = 2
        l_d_mask = (u_char *) 0x80d8a0 ""
        lineend = (u_char *) 0x202944006 "\ne/S\nn/S\n\n\n/D\n\n\n\n\n"
        pos = (u_char *) 0x202944004 "/R\ne/S\nn/S\n\n\n/D\n\n\n\n\n"
        endkey = (u_char *) 0x204729ff8 "URGE"
        keypos = (u_char *) 0x204729ffd "urg" <Address 0x20472a000 out of 
bounds>
        clpos = (struct coldesc *) 0x210399c00
        col = 2
        ftpos = (struct field *) 0x210399870
#2  0x0000000000403692 in makekey (flno=-1, filelist={top = 8425552, names = 
0x809050}, nfiles=1, buffer=0x204729fe8,
    bufend=0x204729fff "g" <Address 0x20472a000 out of bounds>, 
ftbl=0x210399800) at /usr/src/usr.bin/sort/files.c:228
        fileno = 1
        dbdesc = (FILE *) 0x203b56398
        dbkey = {{data = 0x0, size = 0}}
        line = {{data = 0x202944000, size = 7}}
        overflow = 0
        c = 0
#3  0x0000000000403d7d in fsort (binno=-1, depth=0, infiles={top = 8425552, 
names = 0x809050}, nfiles=1, outfp=0x203b56300, ftbl=0x210399800)
    at /usr/src/usr.bin/sort/fsort.c:114
        weights = (u_char *) 0x80d280 "\001\002\003\004\005\006\a\b\t\n"
        keypos = (u_char **) 0x2104043c8
        bufend = (u_char *) 0x204729fff "g" <Address 0x20472a000 out of bounds>
        tmpbuf = (u_char *) 0x1b6 <Address 0x1b6 out of bounds>
        buffer = (u_char *) 0x20462a000 "7"
        keylist = (u_char **) 0x2103db000
        bufsize = 1048576
        ntfiles = 3
        mfct = 0
        total = 0
        i = 8444576
        maxb = 0
        lastb = 1536
        panic = 0
        c = 0
        nelem = 21113
        sizes = {0 <repeats 65 times>, 257626, 191738, 427271, 276348, 174983, 
175893, 109336, 113585, 193643, 29239, 18286, 103809, 189061, 59766, 109610, 
329323,
  21823, 122734, 4658, 1634, 473, 1390, 960, 231, 246, 636, 0 <repeats 166 
times>}
        tfiles = {top = 0, names = 0x100000000}
        mstart = {top = 984, names = 0x3d8}
        get = (int (*)(int, union f_handle, int, RECHEADER *, u_char *, struct 
field *)) 0x403505 <makekey>
        crec = (RECHEADER *) 0x204729fe8
        tfield = {{icol = {p = 0x0, num = 1, indent = 0}, tcol = {p = 0x0, num 
= 0, indent = 0}, flags = 0, mask = 0x0, weights = 0x80d9a0 ""}, {icol = {p = 
0x0,
      num = 0, indent = 0}, tcol = {p = 0x0, num = 0, indent = 0}, flags = 0, 
mask = 0x0, weights = 0x0}}
        prevfp = (FILE *) 0x203b56300
        tailfp = {0x0, 0x0, 0x0, 0x0, 0x0}
#4  0x00000000004070e1 in main (argc=7, argv=0x7f7ffffbfda0) at 
/usr/src/usr.bin/sort/sort.c:304
        get = (int (*)(int, union f_handle, int, RECHEADER *, u_char *, struct 
field *)) 0x403505 <makekey>
        ch = -1
        i = 7
        stdinflag = 0
        tmp = 0
        nfields = 2 '\002'
        cflag = 0 '\0'
        c_warn = 0 '\0'
        mflag = 0 '\0'
        outfile = 0x80daa0 "/dev/stdout"
        outpath = 0x80daa0 "/dev/stdout"
        fldtab = (struct field *) 0x210399800
        ftpos = (struct field *) 0x210399870
        filelist = {top = 8425552, names = 0x809050}
        outfp = (FILE *) 0x203b56300
        p = (void *) 0x202
(gdb)


The second one I've seen affects at least i386 and amd64. The file
that triggers it is a database dump and a bit unwieldy. Trimming out
some lines I can get it to fail on amd64 but not i386, and trimming
another line or two from the second file it works on both.

$ wc ~sthen/sort-bug{,-2}.txt
    2644   88260 1486797 /home/hack/sthen/sort-bug.txt
    1604   78698 1031556 /home/hack/sthen/sort-bug-2.txt
    4248  166958 2518353 total

$ gdb /usr/bin/sort sort.core                                
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd4.6"...
Core was generated by `sort'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/lib/libc.so.53.1...done.
Loaded symbols for /usr/lib/libc.so.53.1
Reading symbols from /usr/libexec/ld.so...done.
Loaded symbols for /usr/libexec/ld.so
#0  memcpy (dst0=0x20aa7d000, src0=0x20b09c000, length=0)
    at /usr/src/lib/libc/string/bcopy.c:91
91                              TLOOP1(*dst++ = *src++);
(gdb) bt
#0  memcpy (dst0=0x20aa7d000, src0=0x20b09c000, length=0)
    at /usr/src/lib/libc/string/bcopy.c:91
#1  0x000000020461f8ab in __sfvwrite (fp=0x204a60300, uio=0x7f7ffffde0d0)
    at /usr/src/lib/libc/stdio/fvwrite.c:147
#2  0x000000020461f69a in fwrite (buf=0x20aa7d000, size=1, count=148439, 
    fp=0x204a60300) at /usr/src/lib/libc/stdio/fwrite.c:68
#3  0x00000000004039b6 in putline (rec=0x20b07b010, fp=0x204a60300)
    at /usr/src/usr.bin/sort/files.c:306
#4  0x0000000000406002 in merge (infl0=984, nfiles=2, get=0x4039d1 <geteasy>, 
    outfp=0x204a60300, put=0x403970 <putline>, ftbl=0x20152d400)
    at /usr/src/usr.bin/sort/msort.c:168
#5  0x0000000000405cf4 in fmerge (binno=0, files={top = 984, names = 0x3d8}, 
    nfiles=2, get=0x4039d1 <geteasy>, outfp=0x204a60300, 
    fput=0x403970 <putline>, ftbl=0x20152d400)
    at /usr/src/usr.bin/sort/msort.c:109
#6  0x000000000040410d in fsort (binno=69, depth=4, infiles=
      {top = 0, names = 0x0}, nfiles=2, outfp=0x204a60300, ftbl=0x20152d400)
    at /usr/src/usr.bin/sort/fsort.c:184
#7  0x00000000004070e1 in main (argc=1, argv=0x7f7ffffded60)
    at /usr/src/usr.bin/sort/sort.c:304
(gdb) bt full
#0  memcpy (dst0=0x20aa7d000, src0=0x20b09c000, length=0)
    at /usr/src/lib/libc/string/bcopy.c:91
        dst = 0x20aa8504a ""
        src = 0x20b09c000 <Address 0x20b09c000 out of bounds>
        t = 13303
#1  0x000000020461f8ab in __sfvwrite (fp=0x204a60300, uio=0x7f7ffffde0d0)
    at /usr/src/lib/libc/stdio/fvwrite.c:147
        len = 46145
        p = 0x20b093fb6 ""
        iov = (struct __siov *) 0x7f7ffffde0d0
        w = 46145
        s = 0
        nl = 0x0
        nlknown = 0
        nldist = 6451
#2  0x000000020461f69a in fwrite (buf=0x20aa7d000, size=1, count=148439, 
    fp=0x204a60300) at /usr/src/lib/libc/stdio/fwrite.c:68
        n = 148439
        uio = {uio_iov = 0x7f7ffffde0c0, uio_iovcnt = 1, uio_resid = 46145}
        iov = {iov_base = 0x20b07b020, iov_len = 148439}
        ret = -135840
#3  0x00000000004039b6 in putline (rec=0x20b07b010, fp=0x204a60300)
    at /usr/src/usr.bin/sort/files.c:306
No locals.
#4  0x0000000000406002 in merge (infl0=984, nfiles=2, get=0x4039d1 <geteasy>, 
    outfp=0x204a60300, put=0x403970 <putline>, ftbl=0x20152d400)
    at /usr/src/usr.bin/sort/msort.c:168
        c = 0
        i = 2
        j = 2
        dummy = {top = 0, names = 0x0}
        flist = {0x201d37000, 0x20b08b020, 0x200000000, 0x0, 0x201405def, 
  0x2045f8292, 0x0, 0x21, 0x10, 0x20040, 0x0, 0x21000, 0x20040, 0x20b07b000, 
  0x21000, 0x204a60398}
        cfile = (struct mfile *) 0x20b07b000
#5  0x0000000000405cf4 in fmerge (binno=0, files={top = 984, names = 0x3d8}, 
    nfiles=2, get=0x4039d1 <geteasy>, outfp=0x204a60300, 
    fput=0x403970 <putline>, ftbl=0x20152d400)
    at /usr/src/usr.bin/sort/msort.c:109
        tout = (FILE *) 0x204a60300
        i = 2
        j = 0
        last = 2
        put = (void (*)(RECHEADER *, FILE *)) 0x403970 <putline>
        l_fstack = (struct tempfile *) 0x80d180
#6  0x000000000040410d in fsort (binno=69, depth=4, infiles=
      {top = 0, names = 0x0}, nfiles=2, outfp=0x204a60300, ftbl=0x20152d400)
    at /usr/src/usr.bin/sort/fsort.c:184
        weights = (u_char *) 0x80d280 "\001\002\003\004\005\006\a\b\t\n"
        keypos = (u_char **) 0x20f9de478
        bufend = (u_char *) 0x2084bbfff ""
        tmpbuf = (u_char *) 0x1b6 <Address 0x1b6 out of bounds>
        buffer = (u_char *) 0x2083bc000 "\"\t"
        keylist = (u_char **) 0x20f9dd000
        bufsize = 1048576
        ntfiles = 0
        mfct = 2
        total = 1498115
        i = 69
        maxb = 69
        lastb = 69
        panic = 4
        c = -1
        nelem = 655
        sizes = {0 <repeats 257 times>}
        tfiles = {top = 0, names = 0x32c00000000}
        mstart = {top = 984, names = 0x3d8}
        get = (int (*)(int, union f_handle, int, RECHEADER *, u_char *, 
    struct field *)) 0x402e38 <getnext>
        crec = (RECHEADER *) 0x20842be58
        tfield = {{icol = {p = 0x0, num = 1, indent = 0}, tcol = {p = 0x0, 
      num = 0, indent = 0}, flags = 0, mask = 0x0, weights = 0x80d9a0 ""}, {
    icol = {p = 0x0, num = 0, indent = 0}, tcol = {p = 0x0, num = 0, 
      indent = 0}, flags = 0, mask = 0x0, weights = 0x0}}
        prevfp = (FILE *) 0x204a60300
        tailfp = {0x0, 0x0, 0x0, 0x0, 0x0}
#7  0x00000000004070e1 in main (argc=1, argv=0x7f7ffffded60)
    at /usr/src/usr.bin/sort/sort.c:304
        get = (int (*)(int, union f_handle, int, RECHEADER *, u_char *, 
    struct field *)) 0x40317e <makeline>
        ch = -1
        i = 1
        stdinflag = 0
        tmp = 0
        nfields = 0 '\0'
        cflag = 0 '\0'
        c_warn = 0 '\0'
        mflag = 0 '\0'
        outfile = 0x80daa0 "/dev/stdout"
        outpath = 0x80daa0 "/dev/stdout"
        fldtab = (struct field *) 0x20152d400
        ftpos = (struct field *) 0x20152d400
        filelist = {top = 8425552, names = 0x809050}
        outfp = (FILE *) 0x204a60300
        p = (void *) 0x202

Reply via email to