• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Tera Termの個人的な作業用リポジトリ


Commit MetaInfo

Revisãof0ef6ab022296419a6ea73253b9e7a444be72343 (tree)
Hora2020-03-17 00:20:53
AutorIWAMOTO Kouichi <sue@iwmt...>
CommiterIWAMOTO Kouichi

Mensagem de Log

チャネル関連のメッセージ送信前にリモートのチャネル番号のチェックを追加した。

Ticket: #40225, #40226
MFT: r8599

問題:

SSH接続で認証直後にウィンドウサイズを変更、またはSend Breakを実行すると
切断される。

原因:

SSH_MSG_CHANNEL_REQUEST で remote id に不正な値をセットして送っていた。

対処:

チャネル関連のメッセージを送信する時に remote id の値をチェックする
ようにした。

git-svn-id: svn+ssh://svn.osdn.net/svnroot/ttssh2/branches/4-stable@8600 f5f01b69-1e22-0410-acbf-894ab4bd6246

Mudança Sumário

Diff

--- a/doc/en/html/about/history.html
+++ b/doc/en/html/about/history.html
@@ -3275,8 +3275,8 @@ SYNOPSIS:
32753275
32763276 <li>Bug fixes
32773277 <ul>
3278- <li>システムのメモリが不足している時、鍵交換時のホスト鍵による署名検証で不正な署名を正しい物として扱う可能性が有
3279-った問題を修正した。</li>
3278+ <!-- li>?V?X?e???̃????????s?????Ă??鎞?A?????????̃z?X?g???ɂ?鏐?????؂ŕs???ȏ????𐳂??????Ƃ??Ĉ????”\?????L?????????C???????B</li -->
3279+ <li>Resizing the VT window immediately after user authentication was completed, connection is closed by server.</li>
32803280 </ul>
32813281 </li>
32823282
--- a/doc/ja/html/about/history.html
+++ b/doc/ja/html/about/history.html
@@ -3282,6 +3282,7 @@
32823282 <li>バグ修正
32833283 <ul>
32843284 <li>システムのメモリが不足している時、鍵交換時のホスト鍵による署名検証で不正な署名を正しい物として扱う可能性が有った問題を修正した。</li>
3285+ <li>ユーザ認証が完了した直後にVTウィンドウのサイズを変更すると、サーバから切断される問題を修正した。</li>
32853286 </ul>
32863287 </li>
32873288
--- a/ttssh2/ttxssh/ssh.c
+++ b/ttssh2/ttxssh/ssh.c
@@ -205,7 +205,7 @@ static Channel_t *ssh2_channel_new(unsigned int window, unsigned int maxpack,
205205 memset(c, 0, sizeof(Channel_t));
206206 c->used = 1;
207207 c->self_id = i;
208- c->remote_id = -1;
208+ c->remote_id = SSH_CHANNEL_INVALID;
209209 c->local_window = window;
210210 c->local_window_max = window;
211211 c->local_consumed = 0;
@@ -3046,11 +3046,16 @@ void SSH_notify_win_size(PTInstVar pvar, int cols, int rows)
30463046 logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
30473047 return;
30483048 }
3049-
3049+ if (c->remote_id == SSH_CHANNEL_INVALID) {
3050+ // この状況は認証完了直後にウィンドウサイズを変更すると発生する。
3051+ // まだシェルのチャネルに対する SSH_MSG_OPEN_CONFIRMATION を受けていないので、
3052+ // 相手側のチャネル番号が判らないので window-change メッセージは送らない。
3053+ logprintf(LOG_LEVEL_WARNING, "%s: remote shell channel number is unknown.", __FUNCTION__);
3054+ return;
3055+ }
30503056
30513057 msg = buffer_init();
30523058 if (msg == NULL) {
3053- // TODO: error check
30543059 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
30553060 return;
30563061 }
@@ -3095,6 +3100,13 @@ int SSH_notify_break_signal(PTInstVar pvar)
30953100 logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
30963101 goto error;
30973102 }
3103+ if (c->remote_id == SSH_CHANNEL_INVALID) {
3104+ // 認証直後に send break を行うと発生する
3105+ // まだシェルのチャネルに対する SSH_MSG_OPEN_CONFIRMATION を受けていないので、
3106+ // 相手側のチャネル番号が判らないので break メッセージは送らない。
3107+ logprintf(LOG_LEVEL_WARNING, "%s: remote shell channel number is unknown.", __FUNCTION__);
3108+ goto error;
3109+ }
30983110
30993111 msg = buffer_init();
31003112 if (msg == NULL) {
@@ -3244,7 +3256,7 @@ void SSH_send(PTInstVar pvar, unsigned char const *buf, unsigned int buflen)
32443256
32453257 } else { // for SSH2(yutaka)
32463258 Channel_t *c = ssh2_channel_lookup(pvar->shell_id);
3247- if (c == NULL) {
3259+ if (c == NULL || c->remote_id == SSH_CHANNEL_INVALID) {
32483260 logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
32493261 }
32503262 else {
@@ -3457,7 +3469,6 @@ void SSH_end(PTInstVar pvar)
34573469 pvar->session_id_len = 0;
34583470
34593471 pvar->userauth_success = 0;
3460- //pvar->remote_id = 0;
34613472 pvar->shell_id = SSH_CHANNEL_INVALID;
34623473 pvar->session_nego_status = 0;
34633474
@@ -3537,7 +3548,6 @@ void SSH2_send_channel_data(PTInstVar pvar, Channel_t *c, unsigned char *buf, un
35373548 if (buflen > 0) {
35383549 msg = buffer_init();
35393550 if (msg == NULL) {
3540- // TODO: error check
35413551 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
35423552 return;
35433553 }
@@ -3666,7 +3676,6 @@ void SSH2_confirm_channel_open(PTInstVar pvar, Channel_t *c)
36663676
36673677 msg = buffer_init();
36683678 if (msg == NULL) {
3669- // TODO: error check
36703679 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
36713680 return;
36723681 }
@@ -3745,7 +3754,6 @@ void SSH2_channel_input_eof(PTInstVar pvar, Channel_t *c)
37453754
37463755 msg = buffer_init();
37473756 if (msg == NULL) {
3748- // TODO: error check
37493757 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
37503758 return;
37513759 }
@@ -3914,7 +3922,6 @@ void SSH_request_X11_forwarding(PTInstVar pvar,
39143922
39153923 msg = buffer_init();
39163924 if (msg == NULL) {
3917- // TODO: error check
39183925 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
39193926 return;
39203927 }
@@ -3924,6 +3931,10 @@ void SSH_request_X11_forwarding(PTInstVar pvar,
39243931 logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
39253932 return;
39263933 }
3934+ if (c->remote_id == SSH_CHANNEL_INVALID) {
3935+ logprintf(LOG_LEVEL_ERROR, "%s: remote shell channel number is unknown.", __FUNCTION__);
3936+ return;
3937+ }
39273938
39283939 // making the fake data
39293940 newlen = 2 * auth_data_len + 1;
@@ -8093,6 +8104,11 @@ static BOOL send_channel_request_gen(PTInstVar pvar, Channel_t *c, unsigned char
80938104
80948105 msg = buffer_init();
80958106 if (msg == NULL) {
8107+ logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
8108+ return FALSE;
8109+ }
8110+ if (c->remote_id == SSH_CHANNEL_INVALID) {
8111+ logprintf(LOG_LEVEL_ERROR, "%s: invalid remote channel number (%d).", __FUNCTION__, c->remote_id);
80968112 return FALSE;
80978113 }
80988114
@@ -8135,13 +8151,11 @@ BOOL send_pty_request(PTInstVar pvar, Channel_t *c)
81358151 // pty open
81368152 msg = buffer_init();
81378153 if (msg == NULL) {
8138- // TODO: error check
81398154 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL. (msg)", __FUNCTION__);
81408155 return FALSE;
81418156 }
81428157 ttymsg = buffer_init();
81438158 if (ttymsg == NULL) {
8144- // TODO: error check
81458159 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL. (ttymsg)", __FUNCTION__);
81468160 buffer_free(msg);
81478161 return FALSE;
@@ -8241,12 +8255,10 @@ static BOOL handle_SSH2_open_confirm(PTInstVar pvar)
82418255
82428256 c = ssh2_channel_lookup(id);
82438257 if (c == NULL) {
8244- // TODO:
82458258 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
82468259 return FALSE;
82478260 }
82488261
8249- // TODO: id check
82508262 remote_id = get_uint32_MSBfirst(data);
82518263 data += 4;
82528264
@@ -8355,7 +8367,6 @@ static BOOL handle_SSH2_open_failure(PTInstVar pvar)
83558367
83568368 c = ssh2_channel_lookup(id);
83578369 if (c == NULL) {
8358- // TODO: SSH2_MSG_DISCONNECTを送る
83598370 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
83608371 return FALSE;
83618372 }
@@ -8498,26 +8509,30 @@ static BOOL handle_SSH2_channel_success(PTInstVar pvar)
84988509 pvar->session_nego_status);
84998510
85008511 if (pvar->session_nego_status == 1) {
8501- // find channel by shell id(2005.2.27 yutaka)
85028512 c = ssh2_channel_lookup(pvar->shell_id);
85038513 if (c == NULL) {
8504- // TODO: error check
85058514 logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
85068515 return FALSE;
85078516 }
8517+ if (c->remote_id == SSH_CHANNEL_INVALID) {
8518+ logprintf(LOG_LEVEL_ERROR, "%s: remote shell channel number is unknown.", __FUNCTION__);
8519+ return FALSE;
8520+ }
85088521 pvar->agentfwd_enable = TRUE;
85098522 return send_pty_request(pvar, c);
85108523
85118524 } else if (pvar->session_nego_status == 2) {
85128525 pvar->session_nego_status = 3;
85138526
8514- // find channel by shell id(2005.2.27 yutaka)
85158527 c = ssh2_channel_lookup(pvar->shell_id);
85168528 if (c == NULL) {
8517- // TODO: error check
85188529 logprintf(LOG_LEVEL_ERROR, "%s: shell channel not found.", __FUNCTION__);
85198530 return FALSE;
85208531 }
8532+ if (c->remote_id == SSH_CHANNEL_INVALID) {
8533+ logprintf(LOG_LEVEL_ERROR, "%s: remote shell channel number is unknown.", __FUNCTION__);
8534+ return FALSE;
8535+ }
85218536
85228537 if (!send_channel_request_gen(pvar, c, "shell", want_reply, NULL, NULL)) {
85238538 return FALSE;;
@@ -8550,7 +8565,6 @@ static BOOL handle_SSH2_channel_failure(PTInstVar pvar)
85508565
85518566 c = ssh2_channel_lookup(channel_id);
85528567 if (c == NULL) {
8553- // TODO: error check
85548568 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, channel_id);
85558569 return FALSE;
85568570 }
@@ -8599,7 +8613,6 @@ static void do_SSH2_adjust_window_size(PTInstVar pvar, Channel_t *c)
85998613 // pty open
86008614 msg = buffer_init();
86018615 if (msg == NULL) {
8602- // TODO: error check
86038616 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
86048617 return;
86058618 }
@@ -8635,7 +8648,6 @@ void ssh2_channel_send_close(PTInstVar pvar, Channel_t *c)
86358648 // SSH2 serverにchannel closeを伝える
86368649 msg = buffer_init();
86378650 if (msg == NULL) {
8638- // TODO: error check
86398651 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
86408652 return;
86418653 }
@@ -9315,10 +9327,13 @@ static BOOL handle_SSH2_channel_data(PTInstVar pvar)
93159327
93169328 c = ssh2_channel_lookup(id);
93179329 if (c == NULL) {
9318- // TODO:
93199330 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
93209331 return FALSE;
93219332 }
9333+ if (c->remote_id == SSH_CHANNEL_INVALID) {
9334+ logprintf(LOG_LEVEL_ERROR, "%s: remote shell channel number is unknown.", __FUNCTION__);
9335+ return FALSE;
9336+ }
93229337
93239338 // string length
93249339 str_len = get_uint32_MSBfirst(data);
@@ -9336,7 +9351,6 @@ static BOOL handle_SSH2_channel_data(PTInstVar pvar)
93369351 "len:%d local_maxpacket:%d", __FUNCTION__, str_len, c->local_maxpacket);
93379352 }
93389353 if (str_len > c->local_window) {
9339- // TODO: logging
93409354 // local window sizeより大きなパケットは捨てる
93419355 logprintf(LOG_LEVEL_WARNING, "%s: Data length is larger than local_window. "
93429356 "len:%d local_window:%d", __FUNCTION__, str_len, c->local_window);
@@ -9400,10 +9414,13 @@ static BOOL handle_SSH2_channel_extended_data(PTInstVar pvar)
94009414
94019415 c = ssh2_channel_lookup(id);
94029416 if (c == NULL) {
9403- // TODO:
94049417 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
94059418 return FALSE;
94069419 }
9420+ if (c->remote_id == SSH_CHANNEL_INVALID) {
9421+ logprintf(LOG_LEVEL_ERROR, "%s: remote shell channel number is unknown.", __FUNCTION__);
9422+ return FALSE;
9423+ }
94079424
94089425 // data_type_code
94099426 data_type = get_uint32_MSBfirst(data);
@@ -9415,12 +9432,10 @@ static BOOL handle_SSH2_channel_extended_data(PTInstVar pvar)
94159432
94169433 // バッファサイズのチェック
94179434 if (strlen > c->local_maxpacket) {
9418- // TODO: logging
94199435 logprintf(LOG_LEVEL_WARNING, "%s: Data length is larger than local_maxpacket. "
94209436 "len:%d local_maxpacket:%d", __FUNCTION__, strlen, c->local_maxpacket);
94219437 }
94229438 if (strlen > c->local_window) {
9423- // TODO: logging
94249439 // local window sizeより大きなパケットは捨てる
94259440 logprintf(LOG_LEVEL_WARNING, "%s: Data length is larger than local_window. "
94269441 "len:%d local_window:%d", __FUNCTION__, strlen, c->local_window);
@@ -9478,7 +9493,6 @@ static BOOL handle_SSH2_channel_eof(PTInstVar pvar)
94789493
94799494 c = ssh2_channel_lookup(id);
94809495 if (c == NULL) {
9481- // TODO:
94829496 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
94839497 return FALSE;
94849498 }
@@ -9596,8 +9610,7 @@ static BOOL handle_SSH2_channel_open(PTInstVar pvar)
95969610
95979611 free(orig_str);
95989612
9599- // X server(port 6000)へ接続する。接続に失敗するとTera Term自身が切断される。
9600- // TODO: 将来、切断されないようにしたい。(2005.7.3 yutaka)
9613+ // X server へ接続する。
96019614 FWD_X11_open(pvar, remote_id, NULL, 0, &chan_num);
96029615
96039616 // channelをアロケートし、必要な情報(remote window size)をここで取っておく。
@@ -9634,7 +9647,6 @@ static BOOL handle_SSH2_channel_open(PTInstVar pvar)
96349647 else {
96359648 msg = buffer_init();
96369649 if (msg == NULL) {
9637- // TODO: error check
96389650 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
96399651 return FALSE;
96409652 }
@@ -9684,7 +9696,6 @@ static BOOL handle_SSH2_channel_close(PTInstVar pvar)
96849696 data += 4;
96859697 c = ssh2_channel_lookup(id);
96869698 if (c == NULL) {
9687- // TODO:
96889699 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
96899700 return FALSE;
96909701 }
@@ -9744,10 +9755,13 @@ static BOOL handle_SSH2_channel_request(PTInstVar pvar)
97449755 data += 4;
97459756 c = ssh2_channel_lookup(id);
97469757 if (c == NULL) {
9747- // TODO:
97489758 logprintf(LOG_LEVEL_ERROR, "%s: channel not found. (%d)", __FUNCTION__, id);
97499759 return FALSE;
97509760 }
9761+ if (c->remote_id == SSH_CHANNEL_INVALID) {
9762+ logprintf(LOG_LEVEL_ERROR, "%s: remote shell channel number is unknown.", __FUNCTION__);
9763+ return FALSE;
9764+ }
97519765
97529766 request = buffer_get_string(&data, NULL);
97539767
@@ -9790,7 +9804,6 @@ static BOOL handle_SSH2_channel_request(PTInstVar pvar)
97909804
97919805 msg = buffer_init();
97929806 if (msg == NULL) {
9793- // TODO: error check
97949807 logprintf(LOG_LEVEL_ERROR, "%s: buffer_init returns NULL.", __FUNCTION__);
97959808 return FALSE;
97969809 }
@@ -9841,6 +9854,10 @@ static BOOL handle_SSH2_window_adjust(PTInstVar pvar)
98419854 logprintf(LOG_LEVEL_WARNING, "%s: channel not found. (%d)", __FUNCTION__, id);
98429855 return TRUE;
98439856 }
9857+ if (c->remote_id == SSH_CHANNEL_INVALID) {
9858+ logprintf(LOG_LEVEL_ERROR, "%s: remote shell channel number is unknown.", __FUNCTION__);
9859+ return FALSE;
9860+ }
98449861
98459862 adjust = get_uint32_MSBfirst(data);
98469863 data += 4;
--- a/ttssh2/ttxssh/ttxssh.h
+++ b/ttssh2/ttxssh/ttxssh.h
@@ -281,7 +281,6 @@ typedef struct _TInstVar {
281281 EVP_CIPHER_CTX *evpcip[MODE_MAX];
282282 int userauth_success;
283283 int shell_id;
284- /*int remote_id;*/
285284 int session_nego_status;
286285 /*
287286 unsigned int local_window;