diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-12-28 21:05:59 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-12-28 21:05:59 +0100 |
| commit | 0fcc7f5f738e38766cde59ffd193643458c26cba (patch) | |
| tree | 44ff1513fbd8e1a238c451dbc6c6b8f020e769c6 /scripts | |
| parent | f1d06462e872270f38c497e36f8cd018ee7415bf (diff) | |
| download | busybox-w32-0fcc7f5f738e38766cde59ffd193643458c26cba.tar.gz busybox-w32-0fcc7f5f738e38766cde59ffd193643458c26cba.tar.bz2 busybox-w32-0fcc7f5f738e38766cde59ffd193643458c26cba.zip | |
scripts/echo.c: fix NUL handling in "abc\0 def"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/echo.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/scripts/echo.c b/scripts/echo.c index 7474ccdd4..e3a07adf0 100644 --- a/scripts/echo.c +++ b/scripts/echo.c | |||
| @@ -153,25 +153,32 @@ int main(int argc, char **argv) | |||
| 153 | if (!eflag) { | 153 | if (!eflag) { |
| 154 | /* optimization for very common case */ | 154 | /* optimization for very common case */ |
| 155 | fputs(arg, stdout); | 155 | fputs(arg, stdout); |
| 156 | } else while ((c = *arg++)) { | 156 | } else |
| 157 | if (c == eflag) { /* Check for escape seq. */ | 157 | while ((c = *arg++) != '\0') { |
| 158 | if (c == eflag) { | ||
| 159 | /* This is an "\x" sequence */ | ||
| 160 | |||
| 158 | if (*arg == 'c') { | 161 | if (*arg == 'c') { |
| 159 | /* '\c' means cancel newline and | 162 | /* "\c" means cancel newline and |
| 160 | * ignore all subsequent chars. */ | 163 | * ignore all subsequent chars. */ |
| 161 | goto ret; | 164 | goto ret; |
| 162 | } | 165 | } |
| 163 | { | 166 | /* Since SUSv3 mandates a first digit of 0, 4-digit octals |
| 164 | /* Since SUSv3 mandates a first digit of 0, 4-digit octals | 167 | * of the form \0### are accepted. */ |
| 165 | * of the form \0### are accepted. */ | 168 | if (*arg == '0') { |
| 166 | if (*arg == '0') { | 169 | if ((unsigned char)(arg[1] - '0') < 8) { |
| 167 | /* NB: don't turn "...\0" into "...\" */ | 170 | /* 2nd char is 0..7: skip leading '0' */ |
| 168 | if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) { | 171 | arg++; |
| 169 | arg++; | ||
| 170 | } | ||
| 171 | } | 172 | } |
| 172 | /* bb_process_escape_sequence handles NUL correctly | 173 | } |
| 173 | * ("...\" case. */ | 174 | /* bb_process_escape_sequence handles NUL correctly |
| 174 | c = bb_process_escape_sequence(&arg); | 175 | * ("...\" case). */ |
| 176 | { | ||
| 177 | /* optimization: don't force arg to be on-stack, | ||
| 178 | * use another variable for that. ~30 bytes win */ | ||
| 179 | const char *z = arg; | ||
| 180 | c = bb_process_escape_sequence(&z); | ||
| 181 | arg = z; | ||
| 175 | } | 182 | } |
| 176 | } | 183 | } |
| 177 | putchar(c); | 184 | putchar(c); |
