bin/58813: Incorrect behavour of sed(1)
Eugene Grosbein
eugen at grosbein.pp.ru
Sat Nov 1 10:20:20 PST 2003
>Number: 58813
>Category: bin
>Synopsis: Incorrect behavour of sed(1)
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sat Nov 01 10:20:17 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: Eugene Grosbein
>Release: FreeBSD 4.9-STABLE i386
>Organization:
Svyaz Service JSC
>Environment:
System: FreeBSD grosbein.pp.ru 4.9-STABLE FreeBSD 4.9-STABLE #25: Thu Oct 30 23:34:44 KRAT 2003 eu at grosbein.pp.ru:/usr/local/obj/usr/local/src/sys/DADV i386
CPUTYPE=i686 and no other optimizations
>Description:
sed(1) can produce incorrect output while processing
long lines. It can produce false error messages.
It can even segfault.
>How-To-Repeat:
Example 1.
perl -e 'print "10: "; print "A" x 2030; print "\n" ' | \
sed -E 's/^([^:]+):(.*)$/<a href=\1>\1<\/a>:\2/' 2>&1 |hd
Writes:
00000000 3c 61 20 68 72 65 66 3d 31 30 3e 31 30 3c 2f 61 |<a href=10>10</a|
00000010 3e 3a 20 41 41 41 41 41 41 41 41 41 41 41 41 41 |>: AAAAAAAAAAAAA|
00000020 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAAAAAAAA|
*
00000800 00 0a |..|
00000802
Note zero byte in last line.
Replace 2030 with 4000 and see:
00000000 3c 61 20 68 72 65 66 3d 31 30 3e 31 30 3c 2f 61 |<a href=10>10</a|
00000010 3e 3a 20 41 41 41 41 41 41 41 41 41 41 41 41 41 |>: AAAAAAAAAAAAA|
00000020 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAAAAAAAA|
*
00000800 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000fb0 00 00 00 0a |....|
00000fb4
Now there are lots of zero characters.
Use 4077 instead of 4000 and get segmentation fault.
Example 2.
perl -e 'print "10: A\n20: "; print "A" x 2542; print "\n\n" ' | \
sed -E 's/^([^:]+)\:(.*)$/<a href=\1>\1<\/a>:\2/' >/dev/null
Writes:
sed: RE error: invalid regular expression
That's not true.
>Fix:
Unknown for me.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list