aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-01-04 03:50:52 -0600
committerRob Landley <rob@landley.net>2015-01-04 03:50:52 -0600
commita8df744605cb95dfb4bdd45ff64f7932166cc907 (patch)
tree680bf4a9cb9f43bf8c33b17c0dc7db780a95fcba /toys/posix
parent77c8d1a7d006e177bd0283b48530a3397b687b6c (diff)
downloadtoybox-a8df744605cb95dfb4bdd45ff64f7932166cc907.tar.gz
Fix sed backslash parsing in square bracket pattern sections.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/sed.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index e9f76d86..8bd309f2 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -675,7 +675,7 @@ static void do_sed(int fd, char *name)
struct step *primal;
if (!fd && *name=='-') {
- error_msg("no -i on stdin");
+ error_msg("-i on stdin");
return;
}
TT.fdout = copy_tempfile(fd, name, &tmp);
@@ -699,7 +699,7 @@ static void do_sed(int fd, char *name)
// if regxex, ignore delimiter in [ranges]
static char *unescape_delimited_string(char **pstr, char *delim, int regex)
{
- char *to, *from, d;
+ char *to, *from, mode = 0, d;
to = from = *pstr;
if (!delim || !*delim) {
@@ -710,21 +710,15 @@ static char *unescape_delimited_string(char **pstr, char *delim, int regex)
} else d = *delim;
to = delim = xmalloc(strlen(*pstr)+1);
- while (*from != d) {
+ while (mode || *from != d) {
if (!*from) return 0;
// delimiter in regex character range doesn't count
if (*from == '[') {
- int len = 1;
-
- if (from[len] == ']') len++;
- while (from[len] != ']') if (!from[len++]) return 0;
- memmove(to, from, ++len);
- to += len;
- from += len;
- continue;
- }
- if (*from == '\\') {
+ mode = '[';
+ if (from[1] == ']') *(to++) = *(from++);
+ } else if (mode && *from == ']') mode = 0;
+ else if (*from == '\\') {
if (!from[1]) return 0;
// Check escaped end delimiter before printf style escapes.
@@ -737,7 +731,7 @@ static char *unescape_delimited_string(char **pstr, char *delim, int regex)
*(to++) = c;
from+=2;
continue;
- }
+ } else if (from[1]) *(to++) = *(from++);
}
}
*(to++) = *(from++);