diff options
author | Ron Yorston <rmy@pobox.com> | 2024-01-12 13:31:24 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-01-12 13:31:24 +0000 |
commit | 72602d763cd164320a27f6db0fedb490cb9b457f (patch) | |
tree | 3d304fcedf0a310165f169386b5af3cff2efb418 | |
parent | cdee4a435a7d0d4abac29ea38f8bee9b53e9830e (diff) | |
download | busybox-w32-72602d763cd164320a27f6db0fedb490cb9b457f.tar.gz busybox-w32-72602d763cd164320a27f6db0fedb490cb9b457f.tar.bz2 busybox-w32-72602d763cd164320a27f6db0fedb490cb9b457f.zip |
lineedit: remove CRs from input
Commit 8ade494aeb (win32: add support for virtual terminal input)
made some changes to how input is handled in the line editing code.
In some circumstances (e.g. 'cat | sh -i') this results in input
being read using fgets(3) rather than from the keyboard. Remove
CRs from input in this case.
Also, use fgets(3) if stdin is not a tty, but not stdout.
-rw-r--r-- | libbb/lineedit.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index efc5f8805..976a7d87d 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -2673,7 +2673,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2673 | #if !ENABLE_PLATFORM_MINGW32 | 2673 | #if !ENABLE_PLATFORM_MINGW32 |
2674 | if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) { | 2674 | if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) { |
2675 | #else | 2675 | #else |
2676 | if (n != 0 || !isatty(0) || !isatty(1)) { | 2676 | if (n != 0 || !isatty(0)) { |
2677 | #endif | 2677 | #endif |
2678 | /* Happens when e.g. stty -echo was run before. | 2678 | /* Happens when e.g. stty -echo was run before. |
2679 | * But if ICANON is not set, we don't come here. | 2679 | * But if ICANON is not set, we don't come here. |
@@ -2684,8 +2684,12 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2684 | fflush_all(); | 2684 | fflush_all(); |
2685 | if (fgets(command, maxsize, stdin) == NULL) | 2685 | if (fgets(command, maxsize, stdin) == NULL) |
2686 | len = -1; /* EOF or error */ | 2686 | len = -1; /* EOF or error */ |
2687 | else | 2687 | else { |
2688 | len = strlen(command); | 2688 | len = strlen(command); |
2689 | #if ENABLE_PLATFORM_MINGW32 | ||
2690 | len = remove_cr(command, len); | ||
2691 | #endif | ||
2692 | } | ||
2689 | DEINIT_S(); | 2693 | DEINIT_S(); |
2690 | return len; | 2694 | return len; |
2691 | } | 2695 | } |