sed: Fix backslash parsing for 'w' command arg
authorBrian Foley <bpfoley@google.com>
Wed, 2 Jan 2019 21:09:45 +0000 (13:09 -0800)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 21 Jan 2019 12:22:31 +0000 (13:22 +0100)
If there's any whitespace between w and the filename, parse_file_cmd
writes to the wrong offset when trying to fix up backslashes.

This can be seen in the asan build with busybox sed -e 'w 0\\'

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/sed.c

index 1054c1302399d75284f0bb8f72bfc7a877865574..cddb0c732bb55ea22c78932a2d02e18769968d86 100644 (file)
@@ -387,7 +387,7 @@ static int parse_file_cmd(/*sed_cmd_t *sed_cmd,*/ const char *filecmdstr, char *
                bb_error_msg_and_die("empty filename");
        *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
        if (hack)
-               (*retval)[idx] = '\\';
+               (*retval)[idx-start] = '\\';
 
        return idx;
 }