[Ttssh2-commit] [9179] Windows Vista以降でVirtual Storeが有効の場合、ホスト鍵の種類が同じで、

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 2月 21日 (日) 12:00:10 JST


Revision: 9179
          https://osdn.net/projects/ttssh2/scm/svn/commits/9179
Author:   youlab
Date:     2021-02-21 12:00:09 +0900 (Sun, 21 Feb 2021)
Log Message:
-----------
Windows Vista以降でVirtual Storeが有効の場合、ホスト鍵の種類が同じで、
鍵の内容が異なるときに、known_hostsからの鍵削除ができない問題を修正した。

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 14:45:22 UTC (rev 9178)
+++ branches/4-stable/doc/en/html/about/history.html	2021-02-21 03:00:09 UTC (rev 9179)
@@ -3284,7 +3284,8 @@
       <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>
+      <li>When the Virtual Store is enabled on Windows Vista or later and the Host key rotation is enabled,  the original host key is accidentally deleted from known_hosts file.</li>
+      <li>When the Virtual Store is enabled on Windows Vista or later and the host key type is same but key contents is different,  the host key can not be deleted from known_hosts file.</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 14:45:22 UTC (rev 9178)
+++ branches/4-stable/doc/ja/html/about/history.html	2021-02-21 03:00:09 UTC (rev 9179)
@@ -3290,7 +3290,8 @@
       <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>
+      <li>Windows Vista\x88ȍ~\x82\xC5Virtual Store\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x82ł\xA9\x82\xC2Host key rotation\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x81Aknown_hosts\x82\xA9\x82猳\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>
+      <li>Windows Vista\x88ȍ~\x82\xC5Virtual Store\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x81A\x83z\x83X\x83g\x8C\xAE\x82̎\xED\x97ނ\xAA\x93\xAF\x82\xB6\x82ŁA\x8C\xAE\x82̓\xE0\x97e\x82\xAA\x88قȂ\xE9\x82Ƃ\xAB\x82ɁAknown_hosts\x82\xA9\x82\xE7\x82̌\xAE\x8D폜\x82\xAA\x82ł\xAB\x82Ȃ\xA2\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 14:45:22 UTC (rev 9178)
+++ branches/4-stable/ttssh2/ttxssh/hosts.c	2021-02-21 03:00:09 UTC (rev 9179)
@@ -1371,42 +1371,31 @@
 		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));
 		begin_read_host_files(pvar, 0);
@@ -1510,39 +1499,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,
-					       length);
 
-				if (amount_written != length) {
-					goto error1;
-				}
+				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;
+
 			}
 			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.");
+				"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);
 	}
 }
 


Ttssh2-commit メーリングリストの案内
Back to archive index