diff --git a/Changes b/Changes index 99ab795ed..74983c020 100644 --- a/Changes +++ b/Changes @@ -1715,3 +1715,4 @@ seen. gmtime warning still there - Added back the commands check that didn't get added in conf3 (lamers beware) - Fixed a typo in the module system +- Fixed exception in scanner on Windows diff --git a/include/threads.h b/include/threads.h index 89fab7930..05eb9286c 100644 --- a/include/threads.h +++ b/include/threads.h @@ -35,14 +35,14 @@ #include typedef pthread_t THREAD; typedef pthread_mutex_t MUTEX; -#define IRCCreateThreadEx(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg) - #define IRCCreateThread(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg) +#define IRCCreateThreadEx(thread, start, arg, id) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg) +#define IRCCreateThread(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg) #define IRCMutexLock(mutex) TDebug(MutexLock); pthread_mutex_lock(&mutex) #define IRCMutexTryLock(mutex) TDebug(MutexTryLock); pthread_mutex_trylock(&mutex); #define IRCMutexUnlock(mutex) TDebug(MutexUnlcok); pthread_mutex_unlock(&mutex) #define IRCCreateMutex(mutex) TDebug(CreateMutex); pthread_mutex_init(&mutex, NULL) #define IRCMutexDestroy(mutex) TDebug(MutexDestroy); pthread_mutex_destroy(&mutex) -#define IRCJoinThread(thread,return) TDebug(JoinThread); pthread_join(thread, return) +#define IRCJoinThread(thread,ppvalue) TDebug(JoinThread); pthread_join(thread, (void **)ppvalue) #define IRCExitThreadEx(value) TDebug(ExitThread); pthread_exit(value) #define IRCExitThread(value) TDebug(ExitThread); pthread_exit(value) #define IRCDetachThread(value) TDebug(DetachThread); pthread_detach(value); @@ -50,16 +50,17 @@ typedef pthread_mutex_t MUTEX; #define IRCThreadSelf() pthread_self() #define IRCThreadEqual(thread1, thread2) pthread_equal(thread1,thread2) #else -typedef unsigned long THREAD; +typedef HANDLE THREAD; typedef HANDLE MUTEX; -#define IRCCreateThreadEx(thread, start, arg) _beginthreadex(NULL, 0, (void *)start, arg, 0, &thread) +typedef unsigned (__stdcall *PTHREAD_START) (void *); +#define IRCCreateThreadEx(thread, start, arg, id) thread = (THREAD)_beginthreadex(NULL, 0, (PTHREAD_START)start, arg, 0, id) #define IRCCreateThread(thread, start, arg) thread = _beginthread((void *)start, 0, arg) #define IRCMutexLock(mutex) WaitForSingleObject(mutex, INFINITE) #define IRCMutexTryLock(mutex) WaitForSingleObject(mutex, 0) #define IRCMutexUnlock(mutex) ReleaseMutex(mutex) #define IRCCreateMutex(mutex) mutex = CreateMutex(NULL, FALSE, NULL) #define IRCMutexDestroy(mutex) CloseHandle(mutex) -#define IRCJoinThread(thread,return) { WaitForSingleObject((HANDLE)thread, INFINITE); GetExitCodeThread((HANDLE)thread, (DWORD)return); CloseHandle((HANDLE)thread); } +#define IRCJoinThread(thread,pdwRc) { WaitForSingleObject((HANDLE)thread, INFINITE); GetExitCodeThread((HANDLE)thread, pdwRc); CloseHandle((HANDLE)thread); } #define IRCExitThreadEx(value) _endthreadex((unsigned int)value) #define IRCExitThread(value) _endthread() #define IRCTerminateThread(thread, value) TerminateThread((HANDLE)thread, value) diff --git a/src/modules/scan_http.c b/src/modules/scan_http.c index 56f2691c9..88036b0c3 100644 --- a/src/modules/scan_http.c +++ b/src/modules/scan_http.c @@ -150,31 +150,39 @@ int scan_http_Unload(int module_unload) void scan_http_scan(Scan_AddrStruct *h) { THREAD thread[3]; + unsigned id[3]; + /* note: on windows dwRc holds the thread return code. on unix + ** its a void pointer + */ + DWORD dwRc[3]; HSStruct *p = NULL; IRCMutexLock((h->lock)); + /* First we take 3128 .. */ h->refcnt++; p = MyMalloc(sizeof(HSStruct)); p->hs = h; p->port = 3128; - IRCCreateThreadEx(thread[0], scan_http_scan_port, p); + IRCCreateThreadEx(thread[0], scan_http_scan_port, p, &id[0]); /* Then we take 8080 .. */ h->refcnt++; p = MyMalloc(sizeof(HSStruct)); p->hs = h; p->port = 8080; - IRCCreateThreadEx(thread[1], scan_http_scan_port, p); + IRCCreateThreadEx(thread[1], scan_http_scan_port, p, &id[1]); /* And then we try to infect them with Code Red .. */ h->refcnt++; p = MyMalloc(sizeof(HSStruct)); p->hs = h; p->port = 80; - IRCCreateThreadEx(thread[2], scan_http_scan_port, p); + IRCCreateThreadEx(thread[2], scan_http_scan_port, p, &id[2]); + IRCMutexUnlock((h->lock)); - IRCJoinThread(thread[0], NULL); - IRCJoinThread(thread[1], NULL); - IRCJoinThread(thread[2], NULL); + + IRCJoinThread(thread[0], &dwRc[0]); + IRCJoinThread(thread[1], &dwRc[1]); + IRCJoinThread(thread[2], &dwRc[2]); IRCMutexLock((h->lock)); h->refcnt--; IRCMutexUnlock((h->lock)); diff --git a/src/modules/scan_socks.c b/src/modules/scan_socks.c index f52e31965..82d4b4d90 100644 --- a/src/modules/scan_socks.c +++ b/src/modules/scan_socks.c @@ -146,14 +146,17 @@ int scan_socks_Unload(int module_unload) void scan_socks_scan(Scan_AddrStruct *h) { THREAD thread[2]; + unsigned id[2]; + DWORD dwRc[2]; + IRCMutexLock((h->lock)); h->refcnt++; - IRCCreateThreadEx(thread[0], scan_socks4_scan, h); + IRCCreateThreadEx(thread[0], scan_socks4_scan, h, &id[0]); h->refcnt++; - IRCCreateThreadEx(thread[1], scan_socks5_scan, h); + IRCCreateThreadEx(thread[1], scan_socks5_scan, h, &id[1]); IRCMutexUnlock((h->lock)); - IRCJoinThread(thread[0], NULL); - IRCJoinThread(thread[1], NULL); + IRCJoinThread(thread[0], &dwRc[0]); + IRCJoinThread(thread[1], &dwRc[1]); IRCMutexLock((h->lock)); h->refcnt--; IRCMutexUnlock((h->lock));