summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko2010-05-12 01:49:04 +0200
committerDenys Vlasenko2010-05-12 01:49:04 +0200
commita2215b98f7d65bc613b9c8f008d79672402c6a07 (patch)
treea522b707160253cba5805279b871cc33dabc24ce /editors
parent94043e8ad2d30cc2199b35d18c853314ade174a3 (diff)
downloadbusybox-a2215b98f7d65bc613b9c8f008d79672402c6a07.zip
busybox-a2215b98f7d65bc613b9c8f008d79672402c6a07.tar.gz
sed: fix a command with multible trailing backslashes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 30ab8c9..4bd6e01 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -487,7 +487,7 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
static void add_cmd(const char *cmdstr)
{
sed_cmd_t *sed_cmd;
- int temp;
+ unsigned len, n;
/* Append this line to any unfinished line from last time. */
if (G.add_cmd_line) {
@@ -496,12 +496,14 @@ static void add_cmd(const char *cmdstr)
cmdstr = G.add_cmd_line = tp;
}
- /* If this line ends with backslash, request next line. */
- temp = strlen(cmdstr);
- if (temp && cmdstr[--temp] == '\\') {
+ /* If this line ends with unescaped backslash, request next line. */
+ n = len = strlen(cmdstr);
+ while (n && cmdstr[n-1] == '\\')
+ n--;
+ if ((len - n) & 1) { /* if odd number of trailing backslashes */
if (!G.add_cmd_line)
G.add_cmd_line = xstrdup(cmdstr);
- G.add_cmd_line[temp] = '\0';
+ G.add_cmd_line[len-1] = '\0';
return;
}
@@ -560,7 +562,7 @@ static void add_cmd(const char *cmdstr)
/* last part (mandatory) will be a command */
if (!*cmdstr)
bb_error_msg_and_die("missing command");
- sed_cmd->cmd = *(cmdstr++);
+ sed_cmd->cmd = *cmdstr++;
cmdstr = parse_cmd_args(sed_cmd, cmdstr);
/* Add the command to the command array */