scmno****@osdn*****
scmno****@osdn*****
2017年 12月 19日 (火) 20:50:14 JST
Revision: 7009 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7009 Author: doda Date: 2017-12-19 20:50:14 +0900 (Tue, 19 Dec 2017) Log Message: ----------- share_key の解放もれを修正。その他コード整理。 ・free() するポインタが NULL かどうかチェックするのを廃止 free(NULL) は何も行わない事が保証されている。 ・正常系と異常系でのリソース解放を共通化。 解放漏れが起きにくくするため。 Modified Paths: -------------- trunk/ttssh2/ttxssh/ssh.c -------------- next part -------------- Modified: trunk/ttssh2/ttxssh/ssh.c =================================================================== --- trunk/ttssh2/ttxssh/ssh.c 2017-12-18 11:06:16 UTC (rev 7008) +++ trunk/ttssh2/ttxssh/ssh.c 2017-12-19 11:50:14 UTC (rev 7009) @@ -5520,6 +5520,7 @@ char *emsg, emsg_tmp[1024]; // error message int ret, hashlen; Key *hostkey; // hostkey + BOOL result = FALSE; logputs(LOG_LEVEL_VERBOSE, "SSH2_MSG_KEXDH_REPLY was received."); @@ -5705,22 +5706,19 @@ SSH2_dispatch_add_message(SSH2_MSG_IGNORE); // XXX: Tru64 UNIX workaround (2005.3.5 yutaka) SSH2_dispatch_add_message(SSH2_MSG_DEBUG); - BN_free(dh_server_pub); - DH_free(pvar->kexdh); pvar->kexdh = NULL; - key_free(hostkey); - if (dh_buf != NULL) free(dh_buf); - return TRUE; + result = TRUE; error: BN_free(dh_server_pub); DH_free(pvar->kexdh); pvar->kexdh = NULL; key_free(hostkey); - if (dh_buf != NULL) free(dh_buf); + free(dh_buf); BN_free(share_key); - notify_fatal_error(pvar, emsg, TRUE); + if (result == FALSE) + notify_fatal_error(pvar, emsg, TRUE); - return FALSE; + return result; } @@ -5745,6 +5743,7 @@ char *emsg, emsg_tmp[1024]; // error message int ret, hashlen; Key *hostkey = NULL; // hostkey + BOOL result = FALSE; logputs(LOG_LEVEL_VERBOSE, "SSH2_MSG_KEX_DH_GEX_REPLY was received."); @@ -5939,22 +5938,19 @@ SSH2_dispatch_add_message(SSH2_MSG_IGNORE); // XXX: Tru64 UNIX workaround (2005.3.5 yutaka) SSH2_dispatch_add_message(SSH2_MSG_DEBUG); - BN_free(dh_server_pub); - DH_free(pvar->kexdh); pvar->kexdh = NULL; - key_free(hostkey); - if (dh_buf != NULL) free(dh_buf); - return TRUE; + result = TRUE; error: BN_free(dh_server_pub); DH_free(pvar->kexdh); pvar->kexdh = NULL; key_free(hostkey); - if (dh_buf != NULL) free(dh_buf); + free(dh_buf); BN_free(share_key); - notify_fatal_error(pvar, emsg, TRUE); + if (result == FALSE) + notify_fatal_error(pvar, emsg, TRUE); - return FALSE; + return result; } @@ -5978,6 +5974,7 @@ char *emsg, emsg_tmp[1024]; // error message int ret, hashlen; Key *hostkey = NULL; // hostkey + BOOL result = FALSE; logputs(LOG_LEVEL_VERBOSE, "SSH2_MSG_KEX_ECDH_REPLY was received."); @@ -6185,22 +6182,19 @@ SSH2_dispatch_add_message(SSH2_MSG_IGNORE); // XXX: Tru64 UNIX workaround (2005.3.5 yutaka) SSH2_dispatch_add_message(SSH2_MSG_DEBUG); - EC_KEY_free(pvar->ecdh_client_key); pvar->ecdh_client_key = NULL; - EC_POINT_clear_free(server_public); - key_free(hostkey); - if (ecdh_buf != NULL) free(ecdh_buf); - return TRUE; + result = TRUE; error: + EC_KEY_free(pvar->ecdh_client_key); pvar->ecdh_client_key = NULL; EC_POINT_clear_free(server_public); - EC_KEY_free(pvar->ecdh_client_key); pvar->ecdh_client_key = NULL; key_free(hostkey); - if (ecdh_buf != NULL) free(ecdh_buf); + free(ecdh_buf); BN_free(share_key); - notify_fatal_error(pvar, emsg, TRUE); + if (result == FALSE) + notify_fatal_error(pvar, emsg, TRUE); - return FALSE; + return result; }