diff options
| author | Ron Yorston <rmy@pobox.com> | 2025-07-07 12:39:16 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2025-07-07 12:39:16 +0100 |
| commit | 1d659554ca999c4d5ad1793d5007526f84fdac89 (patch) | |
| tree | 68231f209c42233b3746ee418d2e2e530c310c19 /shell/shell_common.c | |
| parent | 3a614be62f1f17d2269adacb699faf2aa2877568 (diff) | |
| download | busybox-w32-1d659554ca999c4d5ad1793d5007526f84fdac89.tar.gz busybox-w32-1d659554ca999c4d5ad1793d5007526f84fdac89.tar.bz2 busybox-w32-1d659554ca999c4d5ad1793d5007526f84fdac89.zip | |
shell: avoid miscounting backslashes in read built-in
When the '-n' option was used to limit the number of characters
read, any backslashes in the input weren't correctly accounted
for.
Adds 16 bytes.
(GitHub issue #504)
Diffstat (limited to 'shell/shell_common.c')
| -rw-r--r-- | shell/shell_common.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c index 6ea08ad74..2702ef98a 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c | |||
| @@ -295,7 +295,7 @@ shell_builtin_read(struct builtin_read_params *params) | |||
| 295 | * and exit BS context. | 295 | * and exit BS context. |
| 296 | * - CR LF not in BS context: replace CR with LF */ | 296 | * - CR LF not in BS context: replace CR with LF */ |
| 297 | buffer[--bufpos] = c; | 297 | buffer[--bufpos] = c; |
| 298 | ++nchars; | 298 | nchars += 1 + (backslash == 2); |
| 299 | } | 299 | } |
| 300 | } else if (backslash == 2) { | 300 | } else if (backslash == 2) { |
| 301 | /* We saw BS CR ??, keep escaped CR, exit BS context, | 301 | /* We saw BS CR ??, keep escaped CR, exit BS context, |
| @@ -315,6 +315,9 @@ shell_builtin_read(struct builtin_read_params *params) | |||
| 315 | backslash = 0; | 315 | backslash = 0; |
| 316 | if (c != '\n') | 316 | if (c != '\n') |
| 317 | goto put; | 317 | goto put; |
| 318 | #if ENABLE_PLATFORM_MINGW32 | ||
| 319 | ++nchars; | ||
| 320 | #endif | ||
| 318 | continue; | 321 | continue; |
| 319 | } | 322 | } |
| 320 | if (c == '\\') { | 323 | if (c == '\\') { |
| @@ -355,7 +358,7 @@ shell_builtin_read(struct builtin_read_params *params) | |||
| 355 | } | 358 | } |
| 356 | put: | 359 | put: |
| 357 | bufpos++; | 360 | bufpos++; |
| 358 | } while (--nchars); | 361 | } while (IF_PLATFORM_MINGW32(backslash ||) --nchars); |
| 359 | 362 | ||
| 360 | if (argv[0]) { | 363 | if (argv[0]) { |
| 361 | /* Remove trailing space $IFS chars */ | 364 | /* Remove trailing space $IFS chars */ |
