From 48d474f78c5f68471bf412a7dbf508ef52f77664 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 22 Aug 2024 15:15:14 +0200 Subject: [PATCH] ttyopts: Adjust the default TTY modes to be sane The "sane" default is now based on the man stty "sane" alias with addition of utf8. Fixes: #270 Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/ttyopts.c | 11 +++++++---- tests/client/torture_request_pty_modes.c | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ttyopts.c b/src/ttyopts.c index 58851916..a1ab31f0 100644 --- a/src/ttyopts.c +++ b/src/ttyopts.c @@ -318,6 +318,9 @@ encode_termios_opts(struct termios *attr, unsigned char *buf, size_t buflen) * This function intentionally doesn't use the \c termios structure * to allow it to work on Windows as well. * + * The "sane" default set is derived from the `stty sane`, but iutf8 support is + * added on top of that. + * * @param[out] buf Modes will be encoded into this buffer. * * @param[in] buflen The length of the buffer. @@ -342,7 +345,7 @@ encode_default_opts(unsigned char *buf, size_t buflen) SSH_ENCODE_OPT(TTY_OP_VQUIT, 034) SSH_ENCODE_OPT(TTY_OP_VERASE, 0177) SSH_ENCODE_OPT(TTY_OP_VKILL, 025) - SSH_ENCODE_OPT(TTY_OP_VEOF, 0) + SSH_ENCODE_OPT(TTY_OP_VEOF, 004) SSH_ENCODE_OPT(TTY_OP_VEOL, 0) SSH_ENCODE_OPT(TTY_OP_VEOL2, 0) SSH_ENCODE_OPT(TTY_OP_VSTART, 021) @@ -359,7 +362,7 @@ encode_default_opts(unsigned char *buf, size_t buflen) SSH_ENCODE_OPT(TTY_OP_ISTRIP, 0) SSH_ENCODE_OPT(TTY_OP_INLCR, 0) SSH_ENCODE_OPT(TTY_OP_IGNCR, 0) - SSH_ENCODE_OPT(TTY_OP_ICRNL, 0) + SSH_ENCODE_OPT(TTY_OP_ICRNL, 1) SSH_ENCODE_OPT(TTY_OP_IUCLC, 0) SSH_ENCODE_OPT(TTY_OP_IXON, 1) SSH_ENCODE_OPT(TTY_OP_IXANY, 0) @@ -376,12 +379,12 @@ encode_default_opts(unsigned char *buf, size_t buflen) SSH_ENCODE_OPT(TTY_OP_NOFLSH, 0) SSH_ENCODE_OPT(TTY_OP_TOSTOP, 0) SSH_ENCODE_OPT(TTY_OP_IEXTEN, 1) - SSH_ENCODE_OPT(TTY_OP_ECHOCTL, 0) + SSH_ENCODE_OPT(TTY_OP_ECHOCTL, 1) SSH_ENCODE_OPT(TTY_OP_ECHOKE, 1) SSH_ENCODE_OPT(TTY_OP_PENDIN, 0) SSH_ENCODE_OPT(TTY_OP_OPOST, 1) SSH_ENCODE_OPT(TTY_OP_OLCUC, 0) - SSH_ENCODE_OPT(TTY_OP_ONLCR, 0) + SSH_ENCODE_OPT(TTY_OP_ONLCR, 1) SSH_ENCODE_OPT(TTY_OP_OCRNL, 0) SSH_ENCODE_OPT(TTY_OP_ONOCR, 0) SSH_ENCODE_OPT(TTY_OP_ONLRET, 0) diff --git a/tests/client/torture_request_pty_modes.c b/tests/client/torture_request_pty_modes.c index 6b10eafe..16d9b19c 100755 --- a/tests/client/torture_request_pty_modes.c +++ b/tests/client/torture_request_pty_modes.c @@ -231,8 +231,8 @@ static void torture_request_pty_modes_use_default_modes(void **state) rc = ssh_channel_request_exec(c, "/bin/echo -e '>TEST\\r\\n<'"); assert_ssh_return_code(session, rc); - /* expect the input unmodified */ - string_found = check_channel_output(c, ">TEST\r\n<"); + /* expect the CRLF translated to newline */ + string_found = check_channel_output(c, ">TEST\r\r\n<"); assert_int_equal(string_found, 1); ssh_channel_close(c);