summaryrefslogtreecommitdiffstats
path: root/win/tclWinSock.c
diff options
context:
space:
mode:
authordavygrvy <davygrvy@pobox.com>2002-12-08 15:31:48 (GMT)
committerdavygrvy <davygrvy@pobox.com>2002-12-08 15:31:48 (GMT)
commit9c6a6a68cfa0c1a9f7f1e029607ea8a8926d81eb (patch)
treeaa8c818191d130ba63a26953a6a9bbe1dee99f41 /win/tclWinSock.c
parent25434df7c01e5696ea3b4affeed85ad22d09587b (diff)
downloadtcl-9c6a6a68cfa0c1a9f7f1e029607ea8a8926d81eb.zip
tcl-9c6a6a68cfa0c1a9f7f1e029607ea8a8926d81eb.tar.gz
tcl-9c6a6a68cfa0c1a9f7f1e029607ea8a8926d81eb.tar.bz2
* win/tclWinSock.c (SocketThreadExitHandler, InitSockets): Check
that the tsdPtr is valid before dereferencing as we call it from the exit handler, too [Bug 650353]. Another WSAStartup() loaded version comparison byte swap issue fixed. Although 0x0101 byte swapped is still 0x0101, properly claiming which is major/minor is more correct.
Diffstat (limited to 'win/tclWinSock.c')
-rw-r--r--win/tclWinSock.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index f314408..03900b8 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinSock.c,v 1.33 2002/11/27 22:47:28 davygrvy Exp $
+ * RCS: @(#) $Id: tclWinSock.c,v 1.34 2002/12/08 15:31:59 davygrvy Exp $
*/
#include "tclWinInt.h"
@@ -389,25 +389,27 @@ InitSockets()
/*
* Initialize the winsock library and check the interface
- * version number. We only ask for the 1.1 interface.
- *
- * Note that WSA_VERSION_REQD has major/minor swapped for the API
- * call (as it is supposed to be) and wsaData.wVersion is
- * reversed back for the comparison. Also, note that
- * WSAVERNOTSUPPORTED is not listed in the error table, but
- * simply gets translated to EINVAL by being out-of-range.
+ * version actually loaded. We only ask for the 1.1 interface
+ * and do require that it not be less than 1.1.
*/
#define WSA_VERSION_MAJOR 1
#define WSA_VERSION_MINOR 1
-#define WSA_VERSION_REQD MAKEWORD(WSA_VERSION_MINOR, WSA_VERSION_MAJOR)
+#define WSA_VERSION_REQD MAKEWORD(WSA_VERSION_MAJOR, WSA_VERSION_MINOR)
if ((err = winSock.WSAStartup(WSA_VERSION_REQD, &wsaData)) != 0) {
TclWinConvertWSAError(err);
goto unloadLibrary;
}
- if (((LOBYTE(wsaData.wVersion) << 16) + HIBYTE(wsaData.wVersion))
- < (WSA_VERSION_MAJOR << 16) + WSA_VERSION_MINOR) {
+
+ /*
+ * Note the byte positions are swapped for the comparison, so
+ * that 0x0002 (2.0, MAKEWORD(2,0)) doesn't look less than 0x0101
+ * (1.1). We want the comparison to be 0x0200 < 0x0101.
+ */
+
+ if (MAKEWORD(HIBYTE(wsaData.wVersion), LOBYTE(wsaData.wVersion))
+ < MAKEWORD(WSA_VERSION_MINOR, WSA_VERSION_MAJOR)) {
TclWinConvertWSAError(WSAVERNOTSUPPORTED);
winSock.WSACleanup();
goto unloadLibrary;
@@ -561,7 +563,7 @@ SocketThreadExitHandler(clientData)
ThreadSpecificData *tsdPtr =
(ThreadSpecificData *)TclThreadDataKeyGet(&dataKey);
- if (tsdPtr->socketThread != NULL) {
+ if (tsdPtr != NULL && tsdPtr->socketThread != NULL) {
DWORD exitCode;
GetExitCodeThread(tsdPtr->socketThread, &exitCode);
@@ -579,10 +581,10 @@ SocketThreadExitHandler(clientData)
tsdPtr->socketThread = NULL;
CloseHandle(tsdPtr->readyEvent);
CloseHandle(tsdPtr->socketListLock);
- }
- Tcl_DeleteThreadExitHandler(SocketThreadExitHandler, NULL);
- Tcl_DeleteEventSource(SocketSetupProc, SocketCheckProc, NULL);
+ Tcl_DeleteThreadExitHandler(SocketThreadExitHandler, NULL);
+ Tcl_DeleteEventSource(SocketSetupProc, SocketCheckProc, NULL);
+ }
}
/*