From dc04dba2dd1317000fcbc79ee6d234fd7e7c7e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Wed, 28 Feb 2024 13:37:29 -0500 Subject: [PATCH] Early-out of the channel type loop for channel errors. If there's an error setting the channel or getting the channel type, give up on the session immediately. --- src/sbbs3/answer.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/sbbs3/answer.cpp b/src/sbbs3/answer.cpp index fa548171af..99a72800d0 100644 --- a/src/sbbs3/answer.cpp +++ b/src/sbbs3/answer.cpp @@ -375,19 +375,16 @@ bool sbbs_t::answer() unsigned waits = 0; term_output_disabled = true; do { - int ccid; tnamelen = 0; i=cryptSetAttribute(ssh_session, CRYPT_SESSINFO_SSH_CHANNEL, cid); - if (cryptStatusError(i)) { - log_crypt_error_status_sock(i, "setting channel id"); - } + log_crypt_error_status_sock(i, "setting channel id"); if (cryptStatusOK(i)) { i=cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_SSH_CHANNEL_TYPE, tname, &tnamelen); log_crypt_error_status_sock(i, "getting channel type"); } if (cryptStatusError(i)) { activate_ssh = false; - tnamelen = 0; + break; } if (tnamelen == 7 && strnicmp(tname, "session", 7) == 0) { pthread_mutex_unlock(&ssh_mutex); @@ -409,12 +406,17 @@ bool sbbs_t::answer() pthread_mutex_lock(&ssh_mutex); continue; } - if (tnamelen == 5 && strnicmp(tname, "shell", 5) == 0) { + else if (tnamelen == 5 && strnicmp(tname, "shell", 5) == 0) { term_output_disabled = false; session_channel = cid; } else if (tnamelen == 9 && strncmp(tname, "subsystem", 9) == 0) { i=cryptGetAttributeString(ssh_session, CRYPT_SESSINFO_SSH_CHANNEL_ARG1, tname, &tnamelen); + log_crypt_error_status_sock(i, "getting subsystem argument"); + if (cryptStatusError(i)) { + activate_ssh = false; + break; + } if (((startup->options & (BBS_OPT_ALLOW_SFTP | BBS_OPT_SSH_ANYAUTH)) == BBS_OPT_ALLOW_SFTP) && tnamelen == 4 && strncmp(tname, "sftp", 4) == 0) { if (useron.number) { activate_ssh = init_sftp(cid); @@ -444,13 +446,6 @@ bool sbbs_t::answer() // Fail because there's no session. activate_ssh = false; } - if (cryptStatusOK(i)) { - i=cryptGetAttribute(ssh_session, CRYPT_SESSINFO_SSH_CHANNEL, &ccid); - if (cid == -1) - cid = ccid; - if (cryptStatusOK(i) && ccid != cid) - continue; - } break; } while(1); } -- GitLab