• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision9200 (tree)
Time2021-03-19 00:27:14
Authorzmatsuo

Log Message

DetectComPorts()でバッファオーバーランしないよう修正

- テーブルサイズ(4096)よりcomポート数が多い場合オーバーランしていた
- ttpcmn/ttcmn_cominfo.h を追加

Change Summary

Incremental Difference

--- trunk/teraterm/common/comportinfo.cpp (revision 9199)
+++ trunk/teraterm/common/comportinfo.cpp (revision 9200)
@@ -431,9 +431,9 @@
431431 */
432432 ComPortInfo_t *ComPortInfoGet(int *count, const char *lang)
433433 {
434- OSVERSIONINFO osvi;
434+ OSVERSIONINFOA osvi;
435435 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
436- GetVersionEx(&osvi);
436+ GetVersionExA(&osvi);
437437 bool is_setupapi_supported = true;
438438 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) {
439439 // Windows 95
--- trunk/teraterm/common/ttcommon.h (revision 9199)
+++ trunk/teraterm/common/ttcommon.h (revision 9200)
@@ -38,8 +38,6 @@
3838 #define DllExport __declspec(dllimport)
3939 #endif
4040
41-DllExport int PASCAL DetectComPorts(LPWORD ComPortTable, int ComPortMax, char **ComPortDesc);
42-DllExport int PASCAL CheckComPort(WORD ComPort);
4341 DllExport void PASCAL CopyShmemToTTSet(PTTSet ts);
4442 DllExport void PASCAL CopyTTSetToShmem(PTTSet ts);
4543 DllExport BOOL PASCAL StartTeraTerm(PTTSet ts);
@@ -102,9 +100,9 @@
102100 #define NotifyWarnMessageW(cv, msg, title) NotifyMessageW(cv, msg, title, 2)
103101 #define NotifyErrorMessageW(cv, msg, title) NotifyMessageW(cv, msg, title, 3)
104102
105-#include "../ttpcmn/language.h"
106-
107103 #ifdef __cplusplus
108104 }
109105 #endif
110106
107+#include "../ttpcmn/language.h"
108+#include "../ttpcmn/ttcmn_cominfo.h"
--- trunk/teraterm/ttpcmn/ttcmn_cominfo.c (revision 9199)
+++ trunk/teraterm/ttpcmn/ttcmn_cominfo.c (revision 9200)
@@ -31,6 +31,9 @@
3131 #include "codeconv.h"
3232 #include "comportinfo.h"
3333
34+#define DllExport __declspec(dllexport)
35+#include "ttcmn_cominfo.h"
36+
3437 /**
3538 * COMポートを列挙
3639 *
@@ -49,6 +52,13 @@
4952 {
5053 int count;
5154 int i;
55+
56+ // 以前確保した分を開放する
57+ for (i = 0; i < ComPortMax; i++) {
58+ free(ComPortDesc[i]);
59+ ComPortDesc[i] = NULL;
60+ }
61+
5262 ComPortInfo_t *port_info = ComPortInfoGet(&count, NULL);
5363 const ComPortInfo_t *p = port_info;
5464 for (i = 0; i < count; i++) {
@@ -55,6 +65,10 @@
5565 ComPortTable[i] = p->port_no;
5666 ComPortDesc[i] = ToCharW(p->friendly_name);
5767 p++;
68+ if (i == ComPortMax - 1) {
69+ // テーブルをあふれる
70+ break;
71+ }
5872 }
5973
6074 ComPortInfoFree(port_info, count);
--- trunk/teraterm/ttpcmn/ttcmn_cominfo.h (nonexistent)
+++ trunk/teraterm/ttpcmn/ttcmn_cominfo.h (revision 9200)
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright (C) 2021- TeraTerm Project
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions
7+ * are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright
10+ * notice, this list of conditions and the following disclaimer.
11+ * 2. Redistributions in binary form must reproduce the above copyright
12+ * notice, this list of conditions and the following disclaimer in the
13+ * documentation and/or other materials provided with the distribution.
14+ * 3. The name of the author may not be used to endorse or promote products
15+ * derived from this software without specific prior written permission.
16+ *
17+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#pragma once
30+
31+#include <windows.h>
32+
33+#ifdef __cplusplus
34+extern "C" {
35+#endif
36+
37+#if !defined(DllExport)
38+#define DllExport __declspec(dllimport)
39+#endif
40+
41+DllExport int WINAPI DetectComPorts(LPWORD ComPortTable, int ComPortMax, char **ComPortDesc);
42+DllExport int WINAPI CheckComPort(WORD ComPort);
43+
44+#ifdef __cplusplus
45+}
46+#endif
--- trunk/tools/lscom/CMakeLists.txt (revision 9199)
+++ trunk/tools/lscom/CMakeLists.txt (revision 9200)
@@ -9,6 +9,7 @@
99 main.cpp
1010 iswindowsntkernel.c
1111 #
12+ ../../teraterm/ttpcmn/ttcmn_cominfo.h
1213 ../../teraterm/ttpcmn/ttcmn_cominfo.c
1314 #
1415 ../libs/getopt_mb_uni_src/getopt.c
@@ -33,7 +34,6 @@
3334 ${PACKAGE_NAME}
3435 PRIVATE
3536 common_static
36- #ttpcmn
3737 #
3838 #setupapi
3939 )
--- trunk/tools/lscom/main.cpp (revision 9199)
+++ trunk/tools/lscom/main.cpp (revision 9200)
@@ -32,11 +32,9 @@
3232 #define _CRTDBG_MAP_ALLOC
3333 #include <crtdbg.h>
3434
35-extern "C" {
36-int WINAPI DetectComPorts(LPWORD ComPortTable, int ComPortMax, char **ComPortDesc);
37-}
38-
3935 #include "comportinfo.h"
36+#define DllExport __declspec(dllexport)
37+#include "ttcmn_cominfo.h"
4038
4139 #include "getopt.h"
4240
@@ -159,8 +157,6 @@
159157 #endif
160158 setlocale(LC_ALL, "");
161159
162- int no_newline = 0;
163- int multicast = 0;
164160 bool querydosdevice = false;
165161 bool flag_DetectComPorts = false;
166162 bool flag_fopen = false;
Show on old repository browser