OSDN Git Service

Change to specify explicitly code pages.
[ffftp/ffftp.git] / socketwrapper.c
index dcd54c8..caae589 100644 (file)
@@ -114,11 +114,11 @@ BOOL LoadOpenSSL()
                return FALSE;\r
 #ifdef ENABLE_PROCESS_PROTECTION\r
        // 同梱するOpenSSLのバージョンに合わせてSHA1ハッシュ値を変更すること\r
-       // ssleay32.dll 1.0.0e\r
-       // libssl32.dll 1.0.0e\r
-       RegisterTrustedModuleSHA1Hash("\x4E\xB7\xA0\x22\x14\x4B\x58\x6D\xBC\xF5\x21\x0D\x96\x78\x0D\x79\x7D\x66\xB2\xB0");\r
-       // libeay32.dll 1.0.0e\r
-       RegisterTrustedModuleSHA1Hash("\x01\x32\x7A\xAE\x69\x26\xE6\x58\xC7\x63\x22\x1E\x53\x5A\x78\xBC\x61\xC7\xB5\xC1");\r
+       // ssleay32.dll 1.0.0g\r
+       // libssl32.dll 1.0.0g\r
+       RegisterTrustedModuleSHA1Hash("\x42\x32\x3E\x44\x35\xBC\x98\x6C\x45\xC9\xA2\xB8\x41\xE7\xDA\x7B\x6A\x98\xB2\x28");\r
+       // libeay32.dll 1.0.0g\r
+       RegisterTrustedModuleSHA1Hash("\x3F\xC8\x07\x84\xB3\xF0\x71\x4A\x18\x59\x52\x1F\x99\x09\x65\xB9\x49\xA7\x15\x36");\r
 #endif\r
        g_hOpenSSL = LoadLibrary("ssleay32.dll");\r
        // バージョン固定のためlibssl32.dllの読み込みは脆弱性の原因になり得るので廃止\r
@@ -641,6 +641,8 @@ int FTPS_recv(SOCKET s, char * buf, int len, int flags)
 \r
 // IPv6対応\r
 \r
+const struct in6_addr IN6ADDR_NONE = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};\r
+\r
 typedef struct\r
 {\r
        HANDLE h;\r
@@ -682,7 +684,7 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter)
                                                pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]);\r
                                                pHost->h_addr_list[1] = NULL;\r
                                                memcpy(pHost->h_addr_list[0], &((struct sockaddr_in*)p->ai_addr)->sin_addr, sizeof(struct in_addr));\r
-                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen));\r
+                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in_addr)));\r
                                        }\r
                                        else\r
                                                PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16));\r
@@ -700,7 +702,7 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter)
                                                pHost->h_addr_list[0] = (char*)(&pHost->h_addr_list[2]);\r
                                                pHost->h_addr_list[1] = NULL;\r
                                                memcpy(pHost->h_addr_list[0], &((struct sockaddr_in6*)p->ai_addr)->sin6_addr, sizeof(struct in6_addr));\r
-                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + p->ai_addrlen));\r
+                                               PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(sizeof(struct hostent) + sizeof(char*) * 2 + sizeof(struct in6_addr)));\r
                                        }\r
                                        else\r
                                                PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(WSAENOBUFS << 16));\r
@@ -717,10 +719,11 @@ DWORD WINAPI WSAAsyncGetHostByNameIPv6ThreadProc(LPVOID lpParameter)
        }\r
        else\r
                PostMessage(pData->hWnd, pData->wMsg, (WPARAM)pData->h, (LPARAM)(ERROR_INVALID_FUNCTION << 16));\r
-       free(pData->name);\r
-       free(pData);\r
        // CreateThreadが返すハンドルが重複するのを回避\r
        Sleep(10000);\r
+       CloseHandle(pData->h);\r
+       free(pData->name);\r
+       free(pData);\r
        return 0;\r
 }\r
 \r
@@ -767,7 +770,10 @@ int WSACancelAsyncRequestIPv6(HANDLE hAsyncTaskHandle)
        int Result;\r
        Result = SOCKET_ERROR;\r
        if(TerminateThread(hAsyncTaskHandle, 0))\r
+       {\r
+               CloseHandle(hAsyncTaskHandle);\r
                Result = 0;\r
+       }\r
        return Result;\r
 }\r
 \r
@@ -843,7 +849,7 @@ struct in6_addr inet6_addr(const char* cp)
        {\r
                if(!cp)\r
                {\r
-                       memset(&Result, 0xff, sizeof(Result));\r
+                       memcpy(&Result, &IN6ADDR_NONE, sizeof(struct in6_addr));\r
                        break;\r
                }\r
                if(i >= AfterZero)\r
@@ -867,7 +873,7 @@ struct in6_addr inet6_addr(const char* cp)
                                Result.u.Word[i] = ((Result.u.Word[i] & 0xff00) >> 8) | ((Result.u.Word[i] & 0x00ff) << 8);\r
                                if(strncmp(p, ":", 1) != 0 && strlen(p) > 0)\r
                                {\r
-                                       memset(&Result, 0xff, sizeof(Result));\r
+                                       memcpy(&Result, &IN6ADDR_NONE, sizeof(struct in6_addr));\r
                                        break;\r
                                }\r
                                if(cp = strstr(cp, ":"))\r
@@ -1046,8 +1052,16 @@ BOOL LoadPuTTY()
        RegisterTrustedModuleSHA1Hash("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");\r
 #endif\r
        // デバッグ用\r
-//     g_hPuTTY = LoadLibrary("putty.dll");\r
-       g_hPuTTY = LoadLibrary("C:\\SourceForge\\ffftp\\putty\\Debug\\PuTTY.dll");\r
+#ifdef _DEBUG\r
+       {\r
+               char Path[MAX_PATH];\r
+               GetModuleFileName(NULL, Path, MAX_PATH);\r
+               strcpy(strrchr(Path, '\\'), "\\..\\putty\\Debug\\PuTTY.dll");\r
+               g_hPuTTY = LoadLibrary(Path);\r
+       }\r
+#else\r
+       g_hPuTTY = LoadLibrary("putty.dll");\r
+#endif\r
        if(!g_hPuTTY\r
                || !(p_SFTP_Create = (_SFTP_Create)GetProcAddress(g_hPuTTY, "SFTP_Create"))\r
                || !(p_SFTP_Destroy = (_SFTP_Destroy)GetProcAddress(g_hPuTTY, "SFTP_Destroy"))\r