summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-05-04 12:01:23 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-05-04 12:01:23 (GMT)
commitd489f8278641d1b55d50c3800e86e567d7951153 (patch)
tree17b0b7308e9ec17026b87ccb7a8eb6dd314118a3
parent1c8d056c93bd79b5356acb7646a97a97deb710b5 (diff)
downloadtcl-d489f8278641d1b55d50c3800e86e567d7951153.zip
tcl-d489f8278641d1b55d50c3800e86e567d7951153.tar.gz
tcl-d489f8278641d1b55d50c3800e86e567d7951153.tar.bz2
Cherry-pick/backport [65cc894ac5c24495|65cc894ac5]: fix off-by-one possible buffer overrun when looking for encodings; found by coverity
Use GetModuleHandle() in stead of LoadLibrary() for ntdll, which is already loaded by Cygwin.
-rw-r--r--unix/tclUnixInit.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c
index a873f6e..b1a4b24 100644
--- a/unix/tclUnixInit.c
+++ b/unix/tclUnixInit.c
@@ -14,11 +14,11 @@
#ifdef HAVE_LANGINFO
# include <langinfo.h>
# ifdef __APPLE__
-# if defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1030
+# if defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1030
/* Support for weakly importing nl_langinfo on Darwin. */
-# define WEAK_IMPORT_NL_LANGINFO
+# define WEAK_IMPORT_NL_LANGINFO
extern char *nl_langinfo(nl_item) WEAK_IMPORT_ATTRIBUTE;
-# endif
+# endif
# endif
#endif
#include <sys/resource.h>
@@ -34,7 +34,7 @@
#ifdef __CYGWIN__
DLLIMPORT extern __stdcall unsigned char GetVersionExW(void *);
-DLLIMPORT extern __stdcall void *LoadLibraryW(const void *);
+DLLIMPORT extern __stdcall void *GetModuleHandleW(const void *);
DLLIMPORT extern __stdcall void FreeLibrary(void *);
DLLIMPORT extern __stdcall void *GetProcAddress(void *, const char *);
DLLIMPORT extern __stdcall void GetSystemInfo(void *);
@@ -45,12 +45,12 @@ static const char *const platforms[NUMPLATFORMS] = {
};
#define NUMPROCESSORS 11
-static const char *const processors[NUMPROCESSORS] = {
+static const char *const processors[NUMPROCESSORS] = {
"intel", "mips", "alpha", "ppc", "shx", "arm", "ia64", "alpha64", "msil",
"amd64", "ia32_on_win64"
};
-typedef struct _SYSTEM_INFO {
+typedef struct {
union {
DWORD dwOemId;
struct {
@@ -69,7 +69,7 @@ typedef struct _SYSTEM_INFO {
int wProcessorRevision;
} SYSTEM_INFO;
-typedef struct _OSVERSIONINFOW {
+typedef struct {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
@@ -666,7 +666,7 @@ SearchKnownEncodings(
int left = 0;
int right = sizeof(localeTable)/sizeof(LocaleTable);
- while (left <= right) {
+ while (left < right) {
int test = (left + right)/2;
int code = strcmp(localeTable[test].lang, encoding);
@@ -832,7 +832,7 @@ TclpSetVariables(
*/
CFLocaleRef localeRef;
-
+
if (&CFLocaleCopyCurrent != NULL && &CFLocaleGetIdentifier != NULL &&
(localeRef = CFLocaleCopyCurrent())) {
CFStringRef locale = CFLocaleGetIdentifier(localeRef);
@@ -929,16 +929,13 @@ TclpSetVariables(
#ifdef __CYGWIN__
unameOK = 1;
if (!osInfoInitialized) {
- HANDLE handle = LoadLibraryW(L"NTDLL");
+ HANDLE handle = GetModuleHandleW(L"NTDLL");
int(__stdcall *getversion)(void *) =
(int(__stdcall *)(void *))GetProcAddress(handle, "RtlGetVersion");
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
if (!getversion || getversion(&osInfo)) {
GetVersionExW(&osInfo);
}
- if (handle) {
- FreeLibrary(handle);
- }
osInfoInitialized = 1;
}
@@ -1130,7 +1127,7 @@ TclpGetCStackParams(
stackGrowsDown = StackGrowsDown(NULL);
}
#endif
-
+
/*
* The first time through in a thread: record the "outermost" stack
* frame and inquire with the OS about the stack size.
@@ -1159,7 +1156,7 @@ TclpGetCStackParams(
if (!stackSize) {
/*
* Stack failure: if we didn't already blow up, we are within the
- * safety area. Recheck with the OS in case the stack was grown.
+ * safety area. Recheck with the OS in case the stack was grown.
*/
result = GetStackSize(&stackSize);
if (result != TCL_OK) {