Revision: 9178 https://osdn.net/projects/ttssh2/scm/svn/commits/9178 Author: youlab Date: 2021-02-20 23:45:22 +0900 (Sat, 20 Feb 2021) Log Message: ----------- Windows Vista以降でVirtual Storeが有効の場合、Host key rotationで 元々あったホスト鍵を削除してしまう問題を修正した。 Modified Paths: -------------- branches/4-stable/doc/en/html/about/history.html branches/4-stable/doc/ja/html/about/history.html branches/4-stable/ttssh2/ttxssh/hosts.c -------------- next part -------------- Modified: branches/4-stable/doc/en/html/about/history.html =================================================================== --- branches/4-stable/doc/en/html/about/history.html 2021-02-20 12:22:36 UTC (rev 9177) +++ branches/4-stable/doc/en/html/about/history.html 2021-02-20 14:45:22 UTC (rev 9178) @@ -3284,6 +3284,7 @@ <li>Resizing the VT window immediately after user authentication was completed, connection is closed by server.</li> <li>A part of control is always enabled on SSH authentication dialog.</li> <li>When many files are sent in a batch by using D&D's SCP sending, an error occurs.</li> + <li>When the Virtual Store is enabled on Windows Vista or later, Host key rotation accidentally deletes the original host key.</li> </ul> </li> Modified: branches/4-stable/doc/ja/html/about/history.html =================================================================== --- branches/4-stable/doc/ja/html/about/history.html 2021-02-20 12:22:36 UTC (rev 9177) +++ branches/4-stable/doc/ja/html/about/history.html 2021-02-20 14:45:22 UTC (rev 9178) @@ -3290,6 +3290,7 @@ <li>\x83\x86\x81[\x83U\x94F\x8F\xAA\x8A\xAE\x97\xB9\x82\xB5\x82\xBD\x92\xBC\x8C\xE3\x82\xC9VT\x83E\x83B\x83\x93\x83h\x83E\x82̃T\x83C\x83Y\x82\xF0\x95ύX\x82\xB7\x82\xE9\x82ƁA\x83T\x81[\x83o\x82\xA9\x82\xE7\x90ؒf\x82\xB3\x82\xEA\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li> <li>SSH\x94F\x8F_\x83C\x83A\x83\x8D\x83O\x82ňꕔ\x82̃R\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x82\xAA\x8F\xED\x82ɗL\x8C\xF8\x82ɂȂ\xC1\x82Ă\xA2\x82\xBD</li> <li>D&D\x82ɂ\xE6\x82\xE9SCP\x91\x97\x90M\x82ŁA\x91\xBD\x90\x94\x82̃t\x83@\x83C\x83\x8B\x82\xF0\x88ꊇ\x91\x97\x90M\x82\xB7\x82\xE9\x82ƃG\x83\x89\x81[\x82ɂȂ\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li> + <li>Windows Vista\x88ȍ~\x82\xC5Virtual Store\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x81AHost key rotation\x82Ō\xB3\x81X\x82\xA0\x82\xC1\x82\xBD\x83z\x83X\x83g\x8C\xAE\x82\xF0\x8D폜\x82\xB5\x82Ă\xB5\x82܂\xA4\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li> </ul> </li> Modified: branches/4-stable/ttssh2/ttxssh/hosts.c =================================================================== --- branches/4-stable/ttssh2/ttxssh/hosts.c 2021-02-20 12:22:36 UTC (rev 9177) +++ branches/4-stable/ttssh2/ttxssh/hosts.c 2021-02-20 14:45:22 UTC (rev 9178) @@ -1566,42 +1566,29 @@ Key key; // known_hosts\x82ɓo\x98^\x82\xB3\x82\xEA\x82Ă\xA2\x82錮 int length; char filename[MAX_PATH]; -#if _MSC_VER < 1900 // less than VSC2015(VC14.0) - char tmp[L_tmpnam]; -#endif int fd; int amount_written = 0; int close_result; int data_index = 0; - char buf[FILENAME_MAX]; + char *newfiledata = NULL; + int ret; + struct _stat fileStat; + long newFilePos = 0, totalSize; - // \x8F\x91\x82\xAB\x8D\x9E\x82݈ꎞ\x83t\x83@\x83C\x83\x8B\x82\xF0\x8AJ\x82\xAD -#if _MSC_VER < 1900 // less than VSC2015(VC14.0) - _getcwd(filename, sizeof(filename)); - tmpnam_s(tmp, sizeof(tmp)); - strcat_s(filename, sizeof(filename), tmp); -#else // VSC2015(VC14.0) or later - tmpnam_s(filename, sizeof(filename)); -#endif - fd = _open(filename, - _O_CREAT | _O_WRONLY | _O_SEQUENTIAL | _O_BINARY | _O_TRUNC, - _S_IREAD | _S_IWRITE); - - if (fd == -1) { - if (errno == EACCES) { - UTIL_get_lang_msg("MSG_HOSTS_WRITE_EACCES_ERROR", pvar, - "An error occurred while trying to write the host key.\n" - "You do not have permission to write to the known-hosts file."); - notify_nonfatal_error(pvar, pvar->ts->UIMsg); - } - else { - UTIL_get_lang_msg("MSG_HOSTS_WRITE_ERROR", pvar, - "An error occurred while trying to write the host key.\n" - "The host key could not be written."); - notify_nonfatal_error(pvar, pvar->ts->UIMsg); - } - return; + // known_hosts\x83t\x83@\x83C\x83\x8B\x83T\x83C\x83Y\x82\xF0\x8E擾\x82\xB7\x82\xE9\x81B + get_teraterm_dir_relative_name(filename, sizeof(filename), name); + ret = _stat(filename, &fileStat); + if (ret != 0) { + // error + goto error; } + // \x83t\x83@\x83C\x83\x8B\x83f\x81[\x83^\x82̃\x81\x83\x82\x83\x8A\x82\xF0\x8Am\x95ۂ\xB7\x82\xE9\x81B + totalSize = fileStat.st_size; + newfiledata = malloc(totalSize); + if (newfiledata == NULL) { + // error + goto error; + } // \x83t\x83@\x83C\x83\x8B\x82\xA9\x82\xE7\x93ǂݍ\x9E\x82\xDE memset(&key, 0, sizeof(key)); @@ -1703,39 +1690,65 @@ // \x8F\x91\x82\xAB\x8D\x9E\x82ݏ\x88\x97\x9D if (do_write) { length = pvar->hosts_state.file_data_index - data_index; - amount_written = - _write(fd, pvar->hosts_state.file_data + data_index, + + if ((newFilePos + length) >= totalSize) { + UTIL_get_lang_msg("MSG_HOSTS_WRITE_ERROR", pvar, + "An error occurred while trying to write the host key.\n" + "The host key could not be written."); + notify_nonfatal_error(pvar, pvar->ts->UIMsg); + goto error; + } + + memcpy(newfiledata + newFilePos, + pvar->hosts_state.file_data + data_index, length); + newFilePos += length; - if (amount_written != length) { - goto error1; - } } data_index = pvar->hosts_state.file_data_index; } while (1); // \x8DŌ\xE3\x82܂œǂ\xDE - error1: + finish_read_host_files(pvar, 0); + + // \x8DŌ\xE3\x82Ƀ\x81\x83\x82\x83\x8A\x82\xF0\x89\xF0\x95\xFA\x82\xB5\x82Ă\xA8\x82\xAD\x81B + key_init(&key); + + // known_hosts\x83t\x83@\x83C\x83\x8B\x82ɐV\x82\xB5\x82\xA2\x83t\x83@\x83C\x83\x8B\x83f\x81[\x83^\x82ŏ㏑\x82\xAB\x82\xB7\x82\xE9\x81B + fd = _open(filename, + _O_CREAT | _O_WRONLY | _O_SEQUENTIAL | _O_BINARY | _O_TRUNC, + _S_IREAD | _S_IWRITE); + + if (fd == -1) { + if (errno == EACCES) { + UTIL_get_lang_msg("MSG_HOSTS_WRITE_EACCES_ERROR", pvar, + "An error occurred while trying to write the host key.\n" + "You do not have permission to write to the known-hosts file."); + notify_nonfatal_error(pvar, pvar->ts->UIMsg); + } + else { + UTIL_get_lang_msg("MSG_HOSTS_WRITE_ERROR", pvar, + "An error occurred while trying to write the host key.\n" + "The host key could not be written."); + notify_nonfatal_error(pvar, pvar->ts->UIMsg); + } + goto error; + } + + amount_written = _write(fd, newfiledata, newFilePos); close_result = _close(fd); - if (amount_written != length || close_result == -1) { + if (amount_written != newFilePos || close_result == -1) { UTIL_get_lang_msg("MSG_HOSTS_WRITE_ERROR", pvar, "An error occurred while trying to write the host key.\n" "The host key could not be written."); notify_nonfatal_error(pvar, pvar->ts->UIMsg); - goto error2; + goto error; + } + +error: + if (newfiledata) { + free(newfiledata); } - // \x8F\x91\x82\xAB\x8D\x9E\x82݈ꎞ\x83t\x83@\x83C\x83\x8B\x82\xA9\x82烊\x83l\x81[\x83\x80 - get_teraterm_dir_relative_name(buf, sizeof(buf), name); - _unlink(buf); - rename(filename, buf); - - error2: - _unlink(filename); - - finish_read_host_files(pvar, 0); - - // \x8DŌ\xE3\x82Ƀ\x81\x83\x82\x83\x8A\x82\xF0\x89\xF0\x95\xFA\x82\xB5\x82Ă\xA8\x82\xAD\x81B - key_init(&key); } }