Revision: 8012 https://osdn.net/projects/ttssh2/scm/svn/commits/8012 Author: yutakapon Date: 2019-08-24 13:38:27 +0900 (Sat, 24 Aug 2019) Log Message: ----------- SOCKSサーバからパケット受信する際、タイムアウトした時、サーバから切断された時、 recieveFromSocketTimeout()がエラーリターンしていなかった問題を修正した。 関数の呼び元では、正しくデータが読み込めたものとして動くので、古いデータを参照 して動作していた。 なお、関数で指定したサイズのデータが読めなかった場合は、呼び元でエラーチェックするのが あるべき姿(この修正には含んでいない)。 Modified Paths: -------------- trunk/TTProxy/ProxyWSockHook.h trunk/doc/en/html/about/history.html trunk/doc/ja/html/about/history.html -------------- next part -------------- Modified: trunk/TTProxy/ProxyWSockHook.h =================================================================== --- trunk/TTProxy/ProxyWSockHook.h 2019-08-23 14:13:45 UTC (rev 8011) +++ trunk/TTProxy/ProxyWSockHook.h 2019-08-24 04:38:27 UTC (rev 8012) @@ -1197,24 +1197,42 @@ return _sendToSocket(s, (const unsigned char*) buf, len); } - int recieveFromSocketTimeout(SOCKET s, unsigned char* buffer, int size, int timeout) { + /* + * SOCKS\x83T\x81[\x83o\x82\xA9\x82\xE7\x83f\x81[\x83^\x82\xF0\x8E\xF3\x90M\x82\xB7\x82\xE9 + * + * return: + * 1\x88ȏ\xE3 \x8E\xF3\x90M\x83f\x81[\x83^\x90\x94(byte)\x81Bsize\x82\xE6\x82菬\x82\xB3\x82\xA2\x8Fꍇ\x82\xE0\x82\xA0\x82\xE9\x81B + * -1 SOCKET_ERROR + */ + int recieveFromSocketTimeout(SOCKET s, unsigned char* buffer, int size, int timeout) { int ready = 0; + int ret; + while (!ready) { struct timeval tv = {timeout, 0}; fd_set fd; + int n; + FD_ZERO(&fd); FD_SET(s, &fd); - switch (select((int) (s + 1), &fd, NULL, NULL, timeout > 0 ? &tv : NULL)) { + n = select((int)(s + 1), &fd, NULL, NULL, timeout > 0 ? &tv : NULL); + switch (n) { case SOCKET_ERROR: return SOCKET_ERROR; case 0: - return 0; + // \x8E\xF3\x90M\x83^\x83C\x83\x80\x83A\x83E\x83g\x82̏ꍇ\x82ɂ\xE0\x83G\x83\x89\x81[\x88\xB5\x82\xA2\x82Ƃ\xB7\x82\xE9\x81B + return SOCKET_ERROR; default: ready = FD_ISSET(s, &fd); break; } } - return ORIG_recv(s, (char*) buffer, size, 0); + + // SOCKS\x83T\x81[\x83o\x82\xA9\x82\xE7\x90ؒf\x82\xB3\x82ꂽ\x8Fꍇ\x81Arecv()\x82\xAA0\x82\xF0\x95Ԃ\xB7\x82\xBD\x82߁A\x83G\x83\x89\x81[\x88\xB5\x82\xA2\x82Ƃ\xB7\x82\xE9\x81B + ret = ORIG_recv(s, (char*) buffer, size, 0); + if (ret == 0) + ret = SOCKET_ERROR; + return (ret); } int recieveFromSocket(SOCKET s, unsigned char* buffer, int size) { Modified: trunk/doc/en/html/about/history.html =================================================================== --- trunk/doc/en/html/about/history.html 2019-08-23 14:13:45 UTC (rev 8011) +++ trunk/doc/en/html/about/history.html 2019-08-24 04:38:27 UTC (rev 8012) @@ -4793,6 +4793,7 @@ <ul class="history"> <li>Bug fix: Depending on OS, it's not working correctly. This bug was introduced in 4.103.</li> <li>Bug fix: When the hostname setting is domain, IPv6 and IPv4 faullback does not work well. And also, when you can not connect to the proxy server, Connection refused dialog is shown three times in a row.</li> + <li>Bug fix: When data can not receive from SOCKS server during negotiation with SOCKS4 and 5, the data may not be handled as an error.</li> </ul> <h3 id="ttproxy_1.0.0.24">2016.11.30 (Ver 1.0.0.24)</h3> Modified: trunk/doc/ja/html/about/history.html =================================================================== --- trunk/doc/ja/html/about/history.html 2019-08-23 14:13:45 UTC (rev 8011) +++ trunk/doc/ja/html/about/history.html 2019-08-24 04:38:27 UTC (rev 8012) @@ -4798,6 +4798,7 @@ <ul class="history"> <li>OS\x82ɂ\xE6\x82\xC1\x82Đ\xB3\x82\xB5\x82\xAD\x93\xAE\x8D삵\x82Ȃ\xA2\x95s\x8B\x82\xF0\x8FC\x90\xB3\x81B<a href="#teraterm_4.103">teraterm 4.103</a>\x82ł̃G\x83\x93\x83o\x83O\x81B</li> <li>\x83z\x83X\x83g\x96\xBC\x82̐ݒ肪\x83h\x83\x81\x83C\x83\x93\x82̏ꍇ\x82ɂ\xA8\x82\xA2\x82āAIPv6/IPv4\x83t\x83H\x81[\x83\x8B\x83o\x83b\x83N\x82\xAA\x93\xAE\x8D삵\x82Ȃ\xA2\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B\x82\xA9\x82A\x83v\x83\x8D\x83L\x83V\x83T\x81[\x83o\x82ɐڑ\xB1\x82ł\xAB\x82Ȃ\xA2\x8Fꍇ\x81AConnection refused\x83_\x83C\x83A\x83\x8D\x83O\x82\xAA3\x89\xF1\x98A\x91\xB1\x95\\x8E\xA6\x82\xB3\x82\xEA\x82\xE9\x96\xE2\x91\xE8\x82\xE0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li> + <li>SOCKS4/5\x82ƃl\x83S\x83V\x83G\x81[\x83V\x83\x87\x83\x93\x92\x86\x82ɁASOCKS\x83T\x81[\x83o\x82\xA9\x82\xE7\x83f\x81[\x83^\x8E\xF3\x90M\x82ł\xAB\x82Ȃ\xA2\x8Fꍇ\x81A\x83G\x83\x89\x81[\x88\xB5\x82\xA2\x82ɂł\xAB\x82Ă\xA2\x82Ȃ\xA2\x82\xB1\x82Ƃ\xAA\x82\xA0\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li> </ul> <h3 id="ttproxy_1.0.0.24">2016.11.30 (Ver 1.0.0.24)</h3>