[bsdgrep] fgrepcomp(), ignore case and segfault with unicode locale
Test Rat
ttsestt at gmail.com
Thu Aug 11 21:11:44 UTC 2011
A quick test
$ env -i bsdgrep -Fi without_nls usr.bin/grep/grep.c
$ env -i gnugrep -Fi without_nls usr.bin/grep/grep.c
#ifndef WITHOUT_NLS
#ifndef WITHOUT_NLS
#ifndef WITHOUT_NLS
shows that bsd fgrep already fails to ignore case. And if you throw
a few more options to the mix it'd crash, e.g.
$ env -i LC_CTYPE=en_US.UTF-8 TERM=xterm bsdgrep --color -Fir without_nls usr.bin/grep/
[...]
Program received signal SIGSEGV, Segmentation fault.
0x0000000801007ff2 in memchr (s=0x61167a, c=10, n=18446744073707490297) at /usr/src/lib/libc/string/memchr.c:48
48 if (*p++ == (unsigned char)c)
(gdb) bt
#0 0x0000000801007ff2 in memchr (s=0x61167a, c=10, n=18446744073707490297) at /usr/src/lib/libc/string/memchr.c:48
#1 0x0000000801007b03 in __sfvwrite (fp=0x801247770, uio=0x7fffffffd8f0) at /usr/src/lib/libc/stdio/fvwrite.c:170
#2 0x0000000801007698 in fwrite (buf=0x608c03, size=18446744073709551606, count=1, fp=0x801247770)
at /usr/src/lib/libc/stdio/fwrite.c:95
#3 0x0000000000405498 in printline (line=0x7fffffffdb70, sep=58, matches=0x7fffffffd990, m=9)
at /usr/src/usr.bin/grep/util.c:500
#4 0x0000000000404f51 in procline (l=0x7fffffffdb70, nottext=0) at /usr/src/usr.bin/grep/util.c:381
#5 0x000000000040489f in procfile (fn=0x80140b600 "usr.bin/grep/nls/es_ES.ISO8859-1.msg") at /usr/src/usr.bin/grep/util.c:239
#6 0x00000000004044d7 in grep_tree (argv=0x7fffffffdd30) at /usr/src/usr.bin/grep/util.c:163
#7 0x0000000000403ea9 in main (argc=5, argv=0x7fffffffdd10) at /usr/src/usr.bin/grep/grep.c:689
(gdb) bt f
#0 0x0000000801007ff2 in memchr (s=0x61167a, c=10, n=18446744073707490297) at /usr/src/lib/libc/string/memchr.c:48
p = (const unsigned char *) 0x800000 <Error reading address 0x800000: Bad address>
#1 0x0000000801007b03 in __sfvwrite (fp=0x801247770, uio=0x7fffffffd8f0) at /usr/src/lib/libc/stdio/fvwrite.c:170
len = 18446744073709516159
p = 0x61167a ""
iov = (struct __siov *) 0x7fffffffd8f0
w = 880
s = 880
nl = 0x611679 "\n"
nlknown = 0
nldist = 0
#2 0x0000000801007698 in fwrite (buf=0x608c03, size=18446744073709551606, count=1, fp=0x801247770)
at /usr/src/lib/libc/stdio/fwrite.c:95
n = 18446744073709551606
uio = {uio_iov = 0x7fffffffd8e0, uio_iovcnt = 1, uio_resid = -35457}
iov = {iov_base = 0x608c03, iov_len = 18446744073709551606}
#3 0x0000000000405498 in printline (line=0x7fffffffdb70, sep=58, matches=0x7fffffffd990, m=9)
at /usr/src/usr.bin/grep/util.c:500
a = 99
i = 9
n = 1
#4 0x0000000000404f51 in procline (l=0x7fffffffdb70, nottext=0) at /usr/src/usr.bin/grep/util.c:381
matches = {{rm_so = 0, rm_eo = 11}, {rm_so = 11, rm_eo = 22}, {rm_so = 22, rm_eo = 33}, {rm_so = 33, rm_eo = 44}, {
rm_so = 44, rm_eo = 55}, {rm_so = 55, rm_eo = 66}, {rm_so = 66, rm_eo = 77}, {rm_so = 77, rm_eo = 88}, {rm_so = 88,
rm_eo = 99}, {rm_so = 21131328, rm_eo = 8}, {rm_so = -9696, rm_eo = 32767}, {rm_so = 16101362, rm_eo = 8}, {rm_so = 21131328,
rm_eo = 8}, {rm_so = 16103767, rm_eo = 0}, {rm_so = 37, rm_eo = 0}, {rm_so = 8, rm_eo = 0}, {rm_so = -9632, rm_eo = 32767}, {
rm_so = -8944, rm_eo = 32767}, {rm_so = -9664, rm_eo = 32767}, {rm_so = 16103767, rm_eo = 8}, {rm_so = 6327289, rm_eo = 0}, {
rm_so = 437, rm_eo = 0}, {rm_so = -9584, rm_eo = 10}, {rm_so = 6327200, rm_eo = 0}, {rm_so = -9776, rm_eo = 0}, {
rm_so = 6327290, rm_eo = 0}, {rm_so = -9536, rm_eo = 32767}, {rm_so = 4204252, rm_eo = 0}, {rm_so = -9584, rm_eo = 32767}, {
rm_so = 6327200, rm_eo = 0}, {rm_so = -9352, rm_eo = 32767}, {rm_so = 21004392, rm_eo = 8}}
pmatch = {rm_so = 88, rm_eo = 99}
st = 99
i = 1
c = 1
m = 9
r = 0
#5 0x000000000040489f in procfile (fn=0x80140b600 "usr.bin/grep/nls/es_ES.ISO8859-1.msg") at /usr/src/usr.bin/grep/util.c:239
f = (struct file *) 0x801408068
sb = {st_dev = 745804815, st_ino = 171971, st_mode = 33188, st_nlink = 1, st_uid = 1001, st_gid = 1001,
st_rdev = 4294967295, st_atim = {tv_sec = 1292381124, tv_nsec = 0}, st_mtim = {tv_sec = 1280426577, tv_nsec = 0}, st_ctim = {
tv_sec = 1292381124, tv_nsec = 165601426}, st_size = 526, st_blocks = 2, st_blksize = 4096, st_flags = 0, st_gen = 0,
st_lspare = 0, st_birthtim = {tv_sec = 1292381124, tv_nsec = 165601426}}
ln = {off = 0, len = 89,
dat = 0x608ba0 "$ $FreeBSD: head/usr.bin/grep/nls/es_ES.ISO8859-1.msg 210622 2010-07-29 18:02:57Z gabor $\n$\n$set 1\n$quote \"\n1 \"(entrada estdar)\"\n2 \"no se puede leer el fichero comprimido bzip2\"\n3 \"opci desconocid"...,
file = 0x801427040 "usr.bin/grep/nls/es_ES.ISO8859-1.msg", line_no = 1}
s = 32768
c = 0
t = 8
#6 0x00000000004044d7 in grep_tree (argv=0x7fffffffdd30) at /usr/src/usr.bin/grep/util.c:163
fts = (FTS *) 0x80141b300
p = (FTSENT *) 0x801424240
d = 0x7fffffffdc10 "Àÿÿ\177"
dir = 0x0
c = 0
fts_flags = 14
ok = true
#7 0x0000000000403ea9 in main (argc=5, argv=0x7fffffffdd10) at /usr/src/usr.bin/grep/grep.c:689
aargv = (char **) 0x7fffffffdd30
eargv = (char **) 0x80060eda0
eopts = 0x0
ep = 0x7fffffffdcc0 "ÿÿÿ\177"
l = 34378972320
aargc = 1
eargc = 0
i = 1
c = -1
lastc = 114
needpattern = 1
newarg = 1
prevoptind = 3
--
no local bsdgrep changes
More information about the freebsd-current
mailing list