A missing securetty file is not an error.
[oweals/busybox.git] / editors / sed.c
index 93faf00c26bdba44ef303353f3568210d9f9d1f8..23e9d545bd47dfe48b16e96a384c1b79658036b1 100644 (file)
@@ -178,7 +178,7 @@ static int index_of_next_unescaped_regexp_delim(const struct sed_cmd * const sed
 static int get_address(struct sed_cmd *sed_cmd, const char *str, int *linenum, regex_t **regex)
 {
        char *my_str = xstrdup(str);
-       int idx = 0;
+       int idx = 0, idx_start = 1;
        char olddelimiter;
        olddelimiter = sed_cmd->delimiter;
        sed_cmd->delimiter = '/';
@@ -194,13 +194,17 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *linenum, r
                *linenum = -1;
                idx++;
        }
-       else if (my_str[idx] == '/') {
+       else if (my_str[idx] == '/' || my_str[idx] == '\\') {
+               if (my_str[idx] == '\\') {
+                       idx_start++;
+                       sed_cmd-> delimiter = my_str[++idx];
+               }
                idx = index_of_next_unescaped_regexp_delim(sed_cmd, my_str, ++idx);
                if (idx == -1)
                        error_msg_and_die("unterminated match expression");
                my_str[idx] = '\0';
                *regex = (regex_t *)xmalloc(sizeof(regex_t));
-               xregcomp(*regex, my_str+1, REG_NEWLINE);
+               xregcomp(*regex, my_str+idx_start, REG_NEWLINE);
                idx++; /* so it points to the next character after the last '/' */
        }
        else {
@@ -397,12 +401,14 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd
         */
 
        /* first part (if present) is an address: either a number or a /regex/ */
-       if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/')
+       if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/' || ( cmdstr[idx] == '\\' && cmdstr[idx+1] != '\\'))
                idx = get_address(sed_cmd, cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);
 
        /* second part (if present) will begin with a comma */
-       if (cmdstr[idx] == ',')
-               idx += get_address(sed_cmd, &cmdstr[++idx], &sed_cmd->end_line, &sed_cmd->end_match);
+       if (cmdstr[idx] == ',') {
+               idx++;
+               idx += get_address(sed_cmd, &cmdstr[idx], &sed_cmd->end_line, &sed_cmd->end_match);
+       }
 
        /* skip whitespace before the command */
        while (isspace(cmdstr[idx]))