diff options
author | Todd C. Miller <Todd.Miller@sudo.ws> | 2023-05-11 18:12:54 -0600 |
---|---|---|
committer | Todd C. Miller <Todd.Miller@sudo.ws> | 2023-05-11 18:12:54 -0600 |
commit | cddb91108f493a22170e85a25efcdd64949bf6dd (patch) | |
tree | a176a33b02fb049cbce359347436db9e00886b9a | |
parent | c74709e961750dc2634d2b5d860e1bcbd73aa9c0 (diff) | |
download | sudo-cddb91108f493a22170e85a25efcdd64949bf6dd.tar.gz |
Accept carriage return for EOL in addition to newline.
Since visudo doesn't alter the terminal settings it is possible for
the terminal to have the ONLCR bit set in the output control flags.
In that case, we will get a CR, not a NL when the user presses
enter/return. One way this can happen is if visudo is run in the
background from a shell that supports line editing and the editor
restores the (cbreak-style) terminal mode when it finishes.
-rw-r--r-- | plugins/sudoers/visudo.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 53373bd53..bc9b0645a 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -312,7 +312,7 @@ main(int argc, char *argv[]) continue; if (sp != TAILQ_FIRST(&sudoerslist)) { printf(_("press return to edit %s: "), sp->opath); - while ((ch = getchar()) != EOF && ch != '\n') + while ((ch = getchar()) != EOF && ch != '\r' && ch != '\n') continue; } edit_sudoers(sp, editor, editor_argc, editor_argv, -1); @@ -703,7 +703,7 @@ reparse_sudoers(char *editor, int editor_argc, char **editor_argv, bool modified = false; do { printf(_("press return to edit %s: "), sp->opath); - while ((ch = getchar()) != EOF && ch != '\n') + while ((ch = getchar()) != EOF && ch != '\r' && ch != '\n') continue; edit_sudoers(sp, editor, editor_argc, editor_argv, -1); if (sp->modified) @@ -854,7 +854,7 @@ whatnow(void) for (;;) { (void) fputs(_("What now? "), stdout); choice = getchar(); - for (c = choice; c != '\n' && c != EOF;) + for (c = choice; c != '\r' && c != '\n' && c != EOF;) c = getchar(); switch (choice) { |