Commit Graph

162 Commits

Author SHA1 Message Date
Eric Andersen
46390ed829 Junio Hamano, junio at twinsun dot com writes:
The sed command in busybox 1.0.0-pre8 loses leading whitespace
in 'a' command ('i' and 'c' commands are also affected).  A
patch to fix this is attached at the end of this message.

The following is a transcript that reproduces the problem.  The
first run uses busybox 1.0.0-pre3 as "/bin/sed" command, which
gets the expected result.  Later in the test, /bin/sed symlink
is changed to point at busybox 1.0.0-pre8 and the test script is
run again, which shows the failure.

=== reproduction recipe ===
* Part 1.  Use busybox 1.0.0-pre3 as sed; this works.

root# cd /tmp
root# cat 1.sh
#!/bin/sh

cd /tmp
rm -f ipsec.conf ipsec.conf+
cat >ipsec.conf <<\EOF
version 2.0

config setup
        klipsdebug=none
        plutodebug=none
        plutostderrlog=/dev/null

conn %default
        keyingtries=1
        ...
EOF
sed -e '/^config setup/a\
	nat_traversal=yes' ipsec.conf >ipsec.conf+
mv -f ipsec.conf+ ipsec.conf
root# sh -x 1.sh
+ cd /tmp
+ rm -f ipsec.conf ipsec.conf+
+ cat
+ sed -e /^config setup/a\
        nat_traversal=yes ipsec.conf
+ mv -f ipsec.conf+ ipsec.conf
root# cat ipsec.conf
version 2.0

config setup
        nat_traversal=yes
        klipsdebug=none
        plutodebug=none
        plutostderrlog=/dev/null

conn %default
        keyingtries=1
        ...
root# sed --version
sed: invalid option -- -
BusyBox v1.00-pre3 (2004.02.26-18:47+0000) multi-call binary

Usage: sed [-nef] pattern [files...]

* Part 2.  Continuing from the above, use busybox 1.0.0-pre8
  as sed; this fails.

root# ln -s busybox-pre8 /bin/sed-8
root# mv /bin/sed-8 /bin/sed
root# sed --version
This is not GNU sed version 4.0
root# sed --
BusyBox v1.00-pre8 (2004.03.30-02:44+0000) multi-call binary

Usage: sed [-nef] pattern [files...]
root# sh -x 1.sh
+ cd /tmp
+ rm -f ipsec.conf ipsec.conf+
+ cat
+ sed -e /^config setup/a\
        nat_traversal=yes ipsec.conf
+ mv -f ipsec.conf+ ipsec.conf
root# cat ipsec.conf
version 2.0

config setup
nat_traversal=yes
        klipsdebug=none
        plutodebug=none
        plutostderrlog=/dev/null

conn %default
        keyingtries=1
        ...
root#
=== reproduction recipe ends here ===

This problem was introduced in 1.0.0-pre4.  The problem is that
the command argument parsing code strips leading whitespaces too
aggressively.  When running the above example, the piece of code
in question gets "\n\tnat_traversal=yes" as its argument in
cmdstr variable (shown part in the following patch).  What it
needs to do at this point is to strip the first newline and
nothing else, but it instead strips all the leading whitespaces
at the beginning of the string, thus losing the tab character.
The following patch fixes this.
2004-03-31 11:42:40 +00:00
Eric Andersen
c7bda1ce65 Remove trailing whitespace. Update copyright to include 2004. 2004-03-15 08:29:22 +00:00
Rob Landley
53302f80da Add -i option to sed, to edit files in-place. 2004-02-18 09:54:15 +00:00
Eric Andersen
c06f568dda Rob Landley writes:
While building glibc with busybox as part of the development environment, I
found a bug in glibc's regexec can throw sed into an endless loop.  This
fixes it.  Should I put an #ifdef around it or something?  (Note, this patch
also contains the "this is not gnu sed 4.0" hack I posted earlier, which is
also needed to build glibc...)
2004-02-04 10:57:46 +00:00
Rob Landley
40ec4aeb8e Thinko in s//options. (Whitespace skipping in the wrong place.) 2004-01-04 06:42:14 +00:00
Eric Andersen
52a3c2726e Patch from Matt Kraai:
sed is broken:

 busybox sed -n '/^a/,/^a/p' >output <<EOF
 a
 b
 a
 b
 EOF
 cmp -s output - <<EOF
 a
 b
 a
 EOF

The attached patch fixes it.
2003-12-23 08:53:51 +00:00
Eric Andersen
638da75f4b Fix some warnings that have crept in recently 2003-10-09 08:18:36 +00:00
Glenn L McGrath
586d86cc8c Comaptability with gcc-2.95 2003-10-09 07:22:59 +00:00
Glenn L McGrath
42c25735e6 Patch from Rob Landley;
Moving on to building diffutils, busybox sed needs this patch to get
past the first problem.  (Passing it a multi-line command line argument
with -e works, but if you don't use -e it doesn't break up the multiple
lines...)
2003-10-04 05:27:56 +00:00
Glenn L McGrath
0ad4daa54e Patch from Rob Landley to fix backrefs 2003-10-01 10:26:23 +00:00
Glenn L McGrath
738fb33994 Patch by Rob Landley, fix "newline after edit command" 2003-10-01 06:45:11 +00:00
Glenn L McGrath
aa5a602689 Patch by Rob Landley, work in progress update, fixes lots of bugs,
introduces a few others (but they are being worked on)
2003-10-01 03:06:16 +00:00
Glenn L McGrath
761ec20f81 Fix some typo's, remove some extra free statements 2003-09-24 10:23:39 +00:00
Glenn L McGrath
2570b43e82 Configuration option to define wether to follows GNU sed's behaviour
or the posix standard.
Put the cleanup code back the way it was.
2003-09-16 05:25:43 +00:00
Glenn L McGrath
204ff1cea4 Fix a bug that creapt in recently with substitution subprinting, and add
a test for it.
2003-09-16 01:46:36 +00:00
Glenn L McGrath
977451ef44 Fix a simple mistake with pattern space, and add a test for it 2003-09-15 12:07:48 +00:00
Glenn L McGrath
e3e28d3bb6 Fix some memory allocation problems
----------------------------------------------------------------------
2003-09-15 09:22:04 +00:00
Glenn L McGrath
2eed0e2d47 Add a test for the 'P' command and fix current implementation so it
doesnt permanently modify the pattern space.
2003-09-15 06:28:45 +00:00
Glenn L McGrath
6e5687abc3 A test and fix for the sed 'n' command 2003-09-15 06:12:53 +00:00
Glenn L McGrath
73116311e5 Fix for the sed-append-next-line test 2003-09-15 05:42:05 +00:00
Glenn L McGrath
640c1f547f Fix recursion problem 2003-09-15 04:55:29 +00:00
Glenn L McGrath
294d113adb Memory cleanups and fix for echo "foo" | sed 's/foo/bar/;H;q' 2003-09-14 16:28:08 +00:00
Glenn L McGrath
8417c8c38b Cleanup memory usage 2003-09-14 15:24:18 +00:00
Glenn L McGrath
edc388cf4e The previous fix for 's/a/1/;s/b/2/;t one;p;:one;p' broke the case of
echo fooba | ./busybox sed -n 's/foo//;s/bar/found/p'

I really need to start adding these tests to the testsuite.

keep the substituted and altered flags seperate
2003-09-14 08:52:53 +00:00
Glenn L McGrath
3fe475677a Preserve substitution flag value within the current line.
Fixed the following testcase
# cat strings |./busybox sed -n -f test3.sed
1
1
2
c
c
# cat strings
a
b
c
2003-09-14 07:59:28 +00:00
Glenn L McGrath
f4523562b6 Fix branching commands.
If a label isnt specified, jump to end of script, not the last command
in the script.

Print an error and exit if you try and jump to a non-existant label

Works for the following testcase
# cat strings
a
b
c
d
e
f
g
# cat strings | ./busybox sed -n '/d/b;p'
a
b
c
e
f
g
2003-09-14 06:01:14 +00:00
Glenn L McGrath
8aac05bfe5 Patch from Rob Landley
Fixed a memory leak in add_cmd/add_cmd_str by moving the allocation
of sed_cmd down to where it's actually first needed.
                                                                                
In get_address, if index_of_next_unescaped_regexp_delim ever failed, we
wouldn't notice because the return value was added to idx, which was 
already guaranteed to be > 0.  (This is buried in the changes made when 
I redid get_address to be based on pointer arithmetic, because all the tests 
were gratuitously dereferencing with a constant zero, which wasn't obvious.)
         
Comment in parse_regex_delim was wrong: 's' and 'y' both call it.
 
The reason "sed_cmd->num_backrefs = 0;" isn't needed is that sed_cmd was
allocated with cmalloc, which zeroes memory.

Different handling of space after \ in i...

Different handling of pattern "s/a/b s/c/d"

Cool, resursive reads don't cause a crash. :)

Fixed "sed -f blah filename - < filename" since GNU sed was handling 
both - and filenames on the same line.  (You can even list - more than 
once, although it's immediate EOF...)
2003-09-14 04:06:12 +00:00
Glenn L McGrath
7c59a83a77 Stupid typo 2003-09-14 02:37:46 +00:00
Glenn L McGrath
4dc1d25a30 Fix some memory allocation problems 2003-09-14 01:25:31 +00:00
Glenn L McGrath
f36635cec6 Fix the following testcase by disabling global substitution if the regex
is anchored to the start of line, there can be only one subst.
echo "aah" | sed 's/^a/b/g'
2003-09-13 15:12:22 +00:00
Glenn L McGrath
c18ce373a2 Fix the following testcase by storing the state of the adress match with
the command.
# cat strings
a
b
c
d
e
f
g
# ./busybox sed '1,2d;4,$d' <strings
c
# ./busybox sed '4,$d;1,2d' <strings
# sed '4,$d;1,2d' <strings
c
# sed '1,2d;4,$d' <strings
c
2003-09-13 06:57:39 +00:00
Glenn L McGrath
9b04f1841e Fix the substitution print subcommand, it should only print if its
own substitution matched, not previous ones.
e.g
echo fooba | sed -n 's/foo//;s/bar/found/p'
shouldnt print anything
2003-08-30 04:35:07 +00:00
Glenn L McGrath
91e1978ff0 New commands, 'G' and 'H' 2003-04-26 07:40:07 +00:00
Glenn L McGrath
fc4cb4dbb5 Fix logic error in grouped commands 2003-04-12 16:10:42 +00:00
Glenn L McGrath
d4185b0e15 Fix up indenting 2003-04-11 17:10:23 +00:00
Glenn L McGrath
d7fe39b587 Really fix the 'r' command 2003-04-09 15:52:32 +00:00
Glenn L McGrath
d87a7ac269 Fix the sed 'r' command 2003-04-09 15:26:14 +00:00
Glenn L McGrath
2410386611 fix substitution when replacing with &, we shouldnt check for an escape charcter. Its already been taken care of _somewhere_ else 2003-04-09 07:51:43 +00:00
Glenn L McGrath
bd9b32bc0d Label ends at a newline, update comments, rename linked list field 2003-04-09 01:43:54 +00:00
Glenn L McGrath
8d6395d41a Run through indent 2003-04-08 11:56:11 +00:00
Glenn L McGrath
c1d95076f0 Fixes block commands to correctly identify end of block, recognise the #n directive, fix substitue command when regex isnt specified 2003-04-08 06:42:45 +00:00
Glenn L McGrath
7ce9e247f0 Add hold space commands 'g', 'h', 'x' 2003-04-07 16:04:14 +00:00
Glenn L McGrath
c6adada158 Rename "line" to pattern_space to be more descriptive and closer to the POSIX description 2003-04-07 12:24:44 +00:00
Glenn L McGrath
9a52bb6878 Group common string 2003-03-30 09:38:40 +00:00
Glenn L McGrath
30b47df86b Small fix for sed 'y' command 2003-03-30 08:40:09 +00:00
Glenn L McGrath
f01b46d7dd sed 'y' command, simplify some other code 2003-03-30 08:02:18 +00:00
Glenn L McGrath
0c51832b60 Experimental support for embeded newline. (im evil)
Fix segfault when using 'N' with an odd number of lines.
2003-03-30 03:41:53 +00:00
Glenn L McGrath
a0f0f0cf76 Still fine tunning the printing of the substitute command 2003-03-28 14:11:34 +00:00
Glenn L McGrath
595a6a4199 sed 't' branching command 2003-03-28 08:36:52 +00:00
Glenn L McGrath
ccd43a8301 Fix sed 's' command's 'p' flag, so it can print line twice 2003-03-28 07:44:03 +00:00