aboutsummaryrefslogtreecommitdiff
path: root/editors/sed.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* - reuse strings and messages. Saves about 600Baldot2006-06-071-1/+1
| | | | git-svn-id: svn://busybox.net/trunk/busybox@15325 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Confirming it's not needed.landley2006-06-051-1/+1
| | | | git-svn-id: svn://busybox.net/trunk/busybox@15286 69ca8d6d-28ef-0310-b511-8ec308f3f277
* - use bb functions instead of handrolling stuff.aldot2006-06-031-3/+3
| | | | | | | | | | - add XXX question about supposedly superfluous else clause text data bss dec hex filename 5918 0 0 5918 171e editors/sed.o.orig 5901 0 0 5901 170d editors/sed.o git-svn-id: svn://busybox.net/trunk/busybox@15278 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Change llist_add_* to take the address of the list rather than returning the newlandley2006-05-261-1/+1
| | | | | | | head, and change all the callers. git-svn-id: svn://busybox.net/trunk/busybox@15199 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Yann Morin spotted some leftover flotsam from halfway through the recentlandley2006-05-241-1/+1
| | | | | | | llist.c interface change that accidentally got checked in. My bad. git-svn-id: svn://busybox.net/trunk/busybox@15162 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Minor cleanups: Convert a few calloc() calls to xzalloc, remove unnecessarylandley2006-05-211-2/+2
| | | | | | | memset, collate variable declarations... git-svn-id: svn://busybox.net/trunk/busybox@15156 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Convert sed's static variables to a single global structure.landley2006-05-091-123/+130
| | | | git-svn-id: svn://busybox.net/trunk/busybox@15041 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Move sed over to the generic llist_t for append. Saves about 90 bytes.landley2006-05-081-27/+9
| | | | git-svn-id: svn://busybox.net/trunk/busybox@15040 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Portability patch from rfelker. The bb_asprintf.c thing needs an eventuallandley2006-03-091-1/+1
| | | | | | | | follow up in platform.h to set the #ifdef, but the workaround works for everybody, so... git-svn-id: svn://busybox.net/trunk/busybox@14498 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Robert P. Day removed 8 gazillion occurrences of "extern" on functionlandley2006-03-061-1/+1
| | | | | | | definitions. (That should only be on prototypes.) git-svn-id: svn://busybox.net/trunk/busybox@14457 69ca8d6d-28ef-0310-b511-8ec308f3f277
* - silence warning about "'free_and_close_stuff' used but never defined"aldot2006-03-021-3/+3
| | | | git-svn-id: svn://busybox.net/trunk/busybox@14426 69ca8d6d-28ef-0310-b511-8ec308f3f277
* - fix compilation of sed.aldot2006-03-011-7/+7
| | | | | | | | | | | error: static declaration of 'free_and_close_stuff' follows non-static declaration Tiny whitespace cleanup while at it, also make sure that we don't use CONFIG_ anymore. Rob, hope this is ok w/ you.. git-svn-id: svn://busybox.net/trunk/busybox@14399 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Cleanup patch from Denis Vlasenko. Mostly variants of removing the if(x)landley2006-03-011-4/+2
| | | | | | | from before "if(x) free(x)". git-svn-id: svn://busybox.net/trunk/busybox@14396 69ca8d6d-28ef-0310-b511-8ec308f3f277
* A few changes falling out from the effort to make sed handle embedded NUL bytes.landley2006-02-241-18/+26
| | | | | | | Checking in to reduce the diff between my tree and svn... git-svn-id: svn://busybox.net/trunk/busybox@14254 69ca8d6d-28ef-0310-b511-8ec308f3f277
* just whitespacetimr2006-01-251-1/+1
| | | | git-svn-id: svn://busybox.net/trunk/busybox@13584 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Support # comments after s/// option list.landley2005-11-201-32/+14
| | | | git-svn-id: svn://busybox.net/trunk/busybox@12441 69ca8d6d-28ef-0310-b511-8ec308f3f277
* \0 is a synonym for &. Our own "make allbaseconfig" breaks without this.landley2005-10-301-2/+2
| | | | git-svn-id: svn://busybox.net/trunk/busybox@12076 69ca8d6d-28ef-0310-b511-8ec308f3f277
* split libbb: moved xregcomp separatelly for speed up recompilevodz2005-09-141-1/+1
| | | | git-svn-id: svn://busybox.net/trunk/busybox@11464 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Missing break was screwing up 'y//' command. Bug #248.landley2005-09-021-0/+1
| | | | git-svn-id: svn://busybox.net/trunk/busybox@11312 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Patch from Colin Watson (mangled slightly by Rob Landley):landley2005-05-181-6/+10
| | | | | | | | | | | | | This patch implements the 'T' command in sed. This is a GNU extension, but one of the udev hotplug scripts uses it, so I need it in busybox anyway. Includes a test; 'svn add testsuite/sed/sed-branch-conditional-inverted' after applying. git-svn-id: svn://busybox.net/trunk/busybox@10347 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Doug Swarin pointed out a security bug in the -i option of sed.landley2005-05-181-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the permissions on the temp file are correct to prevent it from being maliciously mangled by passing strangers, (created with 600, opened O_EXCL, etc), the permissions on the _directory_ might not be, and we re-open the file to convert the filehandle to a FILE * (and automatically get an error message and exit if the directory's read-only or out of space or some such). This opens a potential race condition if somebody's using dnotify on the directory, deletes/renames the tempfile, and drops a symlink or something there. Somebody running sed -i as root in a world writeable directory could do damage. I dug up notes on an earlier discussion where we looked at the security implications of this (unfortunately on the #uclibc channel rather than email; I don't have a transcript, just notes-to-self) which pointed out that if the permissions on the directory allow other people's files to be deleted/renamed then the original file is vulnerable to sabotage anyway. However, there are two cases that discussion apparently didn't take into account: 1) Using another user's permissions to damage files in other directories you can't access (standard symlink attack). 2) Reading data another user couldn't otherwise access by having the new file belong to that other user. This patch uses fdopen to convert the filehandle into a FILE *, rather than reopening the file. git-svn-id: svn://busybox.net/trunk/busybox@10346 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Patch from Bernhard Fischer to make a bunch of symbols staticandersen2005-04-161-12/+12
| | | | | | | which were otherwise cluttering the global namespace. git-svn-id: svn://busybox.net/trunk/busybox@10121 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Hiroshi found another bug. Currently sed's $ triggers at end of every file,landley2004-11-251-28/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | and with multiple files SuSv3 says it should only trigger at the end of the LAST file. The trivial fix I tried first broke if the last file is empty. Fixing this properly required restructuring things to create a file list (actually a FILE * list), and then processing it all in one go. (There's probably a smaller way to do this, merging with append_list perhaps. But let's get the behavior correct first.) Note that editing files in place (-i) needs the _old_ behavior, with $ triggering at the end of each file. Here's a test of all the things this patch fixed. gnu and busybox seds produce the same results with this patch, and different without it. echo -n -e "1one\n1two\n1three" > ../test1 echo -n > ../test2 echo -e "3one\n3two\n3three" > ../test3 sed -n "$ p" ../test1 ../test2 ../test3 sed -n "$ p" ../test1 ../test2 sed -i -n "$ p" ../test1 ../test2 ../test3 git-svn-id: svn://busybox.net/trunk/busybox@9530 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Hiroshi Ito found some bugs. The 'c' command (cut and paste) was hardwiredlandley2004-10-301-12/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | to not put a newline at the end (which was backwards, it should have been hardwired _to_ put a newline at the end, whether or not the input line ended with a newline). Test case for that: echo | sed -e '$ctest' And then this would segfault: echo | sed -e 'g' Because pattern_space got freed but the dead pointer was only overwritten in an if statement that didn't trigger if the hold space was empty. Oops. While debugging it, I found out that the hold space is persistent between multiple input files, so I promoted it to a global and added it to the memory cleanup. The relevant test case (to compare with That Other Sed) is: echo -n woo > woo sed -e h -e g woo echo "fish" | sed -e '/woo/h' -e "izap" -e 's/woo/thingy/' -e '/fish/g' woo - And somebody gratuitously stuck in a c99 int8_t type for something that's just a flag, so I grouped the darn ints. git-svn-id: svn://busybox.net/trunk/busybox@9486 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Rob Landley writes:andersen2004-05-261-4/+7
| | | | | | | | | | | | | | add sed -r support. I bumped into a couple of things that want to use extended regular expressions in sed, and it really isn't that hard to add. Can't say I've extensively tested it, but it's small and isn't going to break anything that doesn't use it, so... Rob git-svn-id: svn://busybox.net/trunk/busybox@8870 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Use int instead of char for return type, in theory avoiding a castbug12004-05-161-2/+2
| | | | git-svn-id: svn://busybox.net/trunk/busybox@8845 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Fix for debian bug #248106, should use int for returned getopt value.bug12004-05-101-1/+3
| | | | git-svn-id: svn://busybox.net/trunk/busybox@8819 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Update my email address, document some of my tasks in the AUTHORS filebug12004-04-251-1/+1
| | | | git-svn-id: svn://busybox.net/trunk/busybox@8782 69ca8d6d-28ef-0310-b511-8ec308f3f277
* This sed patch can only be described as "duh". Stat the source file, chmodandersen2004-04-211-1/+1
| | | | | | | | | | | | | | the _destination_ file. (Ah hah! That works _much_ better...) I implemented the behavior, I just forgot to test this corner of it. My fault, sorry... No, gnu sed -i doesn't preverve ownership information. I checked. Permissions, yes, ownership info, no. Rob git-svn-id: svn://busybox.net/trunk/busybox@8776 69ca8d6d-28ef-0310-b511-8ec308f3f277
* So I'm building a linux from scratch system, using a working script to do thisandersen2004-04-211-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | that the _only_ change to is that gnu sed has been replaced with busybox sed. And ncurses' install phase hangs. I trace it down, and it's trying to run gawk. (Insert obligatory doubletake, but this is FSF code we're talking about, so...) It turns out gawk shells out to sed, ala "sed -f /tmp/blah file.h". The /tmp/blah file is basically empty (it contains one character, a newline). So basically, gawk is using sed as "cat". With gnu sed, it works like cat, anyway. With busybox sed, it tests if its command list is empty after parsing the command line, and if the list is empty it takes the first file argument as a sed command string, and if that leaves the file list empty it tries to read the data to operate on from stdin. (Hence the hang, since nothing's coming in on stdin...) It _should_ be testing whether there were any instances of -f or -e, not whether it actually got any commands. Using sed as cat may be kind of stupid, but it's valid and gawk relies on this behavior. Here's a patch to fix it, turning a couple of ints into chars in hopes of saving a bit of the space this adds. Comments? Rob git-svn-id: svn://busybox.net/trunk/busybox@8775 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Larry Doolittle writes:andersen2004-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This is a bulk spelling fix patch against busybox-1.00-pre10. If anyone gets a corrupted copy (and cares), let me know and I will make alternate arrangements. Erik - please apply. Authors - please check that I didn't corrupt any meaning. Package importers - see if any of these changes should be passed to the upstream authors. I glossed over lots of sloppy capitalizations, missing apostrophes, mixed American/British spellings, and German-style compound words. What is "pretect redefined for test" in cmdedit.c? Good luck on the 1.00 release! - Larry git-svn-id: svn://busybox.net/trunk/busybox@8759 69ca8d6d-28ef-0310-b511-8ec308f3f277
* The last patch broke:landley2004-04-011-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | sed -i "/^boo/a fred" ipsec.conf Which works in gnu sed. (And is _supposed_ to strip all the whitespace before "fred".) It also broke: sed -i -e "/^boo/a \\" -e " fred" ipsec.conf I.E. there can legally be spaces between the a and the backslash at the end of the line. And strangely enough, gnu sed accepts the following syntax as well: sed -i "/^boo/a \\ fred" ipsec.conf Which is a way of having the significant whitespace at the start of the line, all on one line. (But notice that the whitespace BEFORE the slash is still stripped, as is the slash itself. And notice that the naieve placement of "\n" there doesn't work, it puts an n at the start of the appended line. The double slashing is for shell escapes because you could escape the quote, you see. It's turned into a single backslash. But \n there is _not_ turned into a newline by the shell. So there.) This makes all three syntaxes work in my tests. I should probably start writing better documentation at some point. I posted my current sedtests.py file to the list, which needs a lot more tests added as well... git-svn-id: svn://busybox.net/trunk/busybox@8680 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Junio Hamano, junio at twinsun dot com writes:andersen2004-03-311-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. git-svn-id: svn://busybox.net/trunk/busybox@8676 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Remove trailing whitespace. Update copyright to include 2004.andersen2004-03-151-3/+3
| | | | git-svn-id: svn://busybox.net/trunk/busybox@8630 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Add -i option to sed, to edit files in-place.landley2004-02-181-7/+54
| | | | git-svn-id: svn://busybox.net/trunk/busybox@8510 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Rob Landley writes:andersen2004-02-041-0/+17
| | | | | | | | | | | 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...) git-svn-id: svn://busybox.net/trunk/busybox@8398 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Thinko in s//options. (Whitespace skipping in the wrong place.)landley2004-01-041-2/+3
| | | | git-svn-id: svn://busybox.net/trunk/busybox@8252 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Patch from Matt Kraai:andersen2003-12-231-2/+4
| | | | | | | | | | | | | | | | | | | | | 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. git-svn-id: svn://busybox.net/trunk/busybox@8161 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Fix some warnings that have crept in recentlyandersen2003-10-091-6/+6
| | | | git-svn-id: svn://busybox.net/trunk/busybox@7620 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Comaptability with gcc-2.95bug12003-10-091-1/+2
| | | | git-svn-id: svn://busybox.net/trunk/busybox@7618 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Patch from Rob Landley;bug12003-10-041-23/+24
| | | | | | | | | | 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...) git-svn-id: svn://busybox.net/trunk/busybox@7600 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Patch from Rob Landley to fix backrefsbug12003-10-011-1/+1
| | | | git-svn-id: svn://busybox.net/trunk/busybox@7586 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Patch by Rob Landley, fix "newline after edit command"bug12003-10-011-2/+3
| | | | git-svn-id: svn://busybox.net/trunk/busybox@7584 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Patch by Rob Landley, work in progress update, fixes lots of bugs,bug12003-10-011-780/+678
| | | | | | | introduces a few others (but they are being worked on) git-svn-id: svn://busybox.net/trunk/busybox@7583 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Fix some typo's, remove some extra free statementsbug12003-09-241-4/+2
| | | | git-svn-id: svn://busybox.net/trunk/busybox@7560 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Configuration option to define wether to follows GNU sed's behaviour bug12003-09-161-26/+36
| | | | | | | | or the posix standard. Put the cleanup code back the way it was. git-svn-id: svn://busybox.net/trunk/busybox@7535 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Fix a bug that creapt in recently with substitution subprinting, and addbug12003-09-161-3/+2
| | | | | | | a test for it. git-svn-id: svn://busybox.net/trunk/busybox@7534 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Fix a simple mistake with pattern space, and add a test for itbug12003-09-151-2/+2
| | | | git-svn-id: svn://busybox.net/trunk/busybox@7529 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Fix some memory allocation problemsbug12003-09-151-18/+21
| | | | | | | ---------------------------------------------------------------------- git-svn-id: svn://busybox.net/trunk/busybox@7527 69ca8d6d-28ef-0310-b511-8ec308f3f277
* Add a test for the 'P' command and fix current implementation so itbug12003-09-151-0/+4
| | | | | | | doesnt permanently modify the pattern space. git-svn-id: svn://busybox.net/trunk/busybox@7521 69ca8d6d-28ef-0310-b511-8ec308f3f277