From 5e5b183b419015f713a10be69627bcd9c8abeba4 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Tue, 29 Jun 2004 05:10:15 +0000 Subject: [PATCH] Client spamming server hotfix svn path=/trunk/boinc/; revision=3713 --- checkin_notes | 9 +++++++++ client/app.C | 18 +++++++++++++++++- lib/shmem.C | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/checkin_notes b/checkin_notes index b5bc1e2705..b0d0c328e2 100755 --- a/checkin_notes +++ b/checkin_notes @@ -14229,3 +14229,12 @@ David 27 June 2004 hostinfo_unix.C lib/ app_ipc.h + +Rom 27 June 2004 + - Prevent the reuse of shared memory segments with ones that are already + in use on Windows. + + client/ + app.C + lib/ + shmem.C diff --git a/client/app.C b/client/app.C index f9b0c7df7e..f2095037b7 100644 --- a/client/app.C +++ b/client/app.C @@ -243,7 +243,23 @@ int ACTIVE_TASK::write_app_init_file(APP_INIT_DATA& aid) { // make a unique key for core/app shared memory segment // #ifdef _WIN32 - sprintf(aid.comm_obj_name, "boinc_%d", slot); + int i = 0; + char szSharedMemoryName[256]; + HANDLE hSharedMemoryHandle; + + do { + memset(szSharedMemoryName, '\0', sizeof(szSharedMemoryName)); + sprintf(szSharedMemoryName, "boinc_%d", slot); + i++; + } while((!(hSharedMemoryHandle = create_shmem(szSharedMemoryName, 1024, NULL))) || (1024 < i)); + + if (hSharedMemoryHandle) + CloseHandle(hSharedMemoryHandle); + + if (1024 < i) + return ERR_SEMOP; + + strcpy(aid.comm_obj_name, szSharedMemoryName); #elif HAVE_SYS_IPC_H aid.shm_key = ftok(init_data_path, slot); #else diff --git a/lib/shmem.C b/lib/shmem.C index bba11c923d..8d078c268f 100755 --- a/lib/shmem.C +++ b/lib/shmem.C @@ -57,6 +57,7 @@ HANDLE create_shmem(LPCTSTR seg_name, int size, void** pp) { hSharedMem = CreateFileMapping(INVALID_HANDLE_VALUE, &security, PAGE_READWRITE, 0, size, seg_name); if (!hSharedMem) return NULL; + if (hSharedMem && (ERROR_ALREADY_EXISTS == GetLastError())) return NULL; pMemPtr = MapViewOfFile( hSharedMem, FILE_MAP_ALL_ACCESS, 0, 0, 0 ); *pp = pMemPtr;