Revision: 1316
http://svn.sourceforge.net/wrapper/?rev=1316&view=rev
Author: mortenson
Date: 2007-04-02 00:30:44 -0700 (Mon, 02 Apr 2007)
Log Message:
-----------
Fix a buffer overflow problem if the Wrapper was launched without explicitly specifying a configuration file.
Add tests of the return values of all malloc calls to catch out of memory errors and recover as gracefully as possible. Bug #1649880.
Modified Paths:
--------------
trunk/wrapper/src/c/Makefile-windows-x86-32.nmake
trunk/wrapper/src/c/logger.c
trunk/wrapper/src/c/logger.h
trunk/wrapper/src/c/property.c
trunk/wrapper/src/c/wrapper.c
trunk/wrapper/src/c/wrapper.h
trunk/wrapper/src/c/wrapper.ico
trunk/wrapper/src/c/wrapperJNI_VC8.sln
trunk/wrapper/src/c/wrapperJNI_VC8.vcproj
trunk/wrapper/src/c/wrapper_VC8.sln
trunk/wrapper/src/c/wrapper_VC8.vcproj
trunk/wrapper/src/c/wrapper_unix.c
trunk/wrapper/src/c/wrapper_win.c
trunk/wrapper/src/c/wrapperjni_unix.c
Removed Paths:
-------------
trunk/wrapper/src/c/Makefile-windows-x86-64.nmake
trunk/wrapper/src/c/makewin64.bat
Property Changed:
----------------
trunk/wrapper/src/c/
Property changes on: trunk/wrapper/src/c
___________________________________________________________________
Name: svn:ignore
- messages.rc
wrapperinfo.c
Debug*
Release*
WrapperJNI___Win??_Debug*
WrapperJNI___Win??_Release*
Wrapper??.aps
Wrapper??.ncb
Wrapper??.opt
Wrapper??.dep
WrapperJNI??.dep
WrapperJNI??.mak
.deps
*.ncb
*.suo
*.user
wrapper32_VC8__Win32_Debug
wrapper32_VC8__Win32_Release
decoderJNI_VC8__Win32_Debug
decoderJNI_VC8__Win32_Release
*.aps
wrapper32.vsprops
wrapper.vsprops
wrapper_VC8__Win32_Release
wrapper_VC8__x64_Debug
wrapper_VC8__x64_Release
wrapperJNI32_VC8__Win32_Release
wrapperJNI64_VC8__Win32_Release
wrapper64_VC8__Win32_Release
+ messages.rc
wrapperinfo.c
Debug*
Release*
WrapperJNI___Win??_Debug*
WrapperJNI___Win??_Release*
Wrapper??.aps
Wrapper??.ncb
Wrapper??.opt
Wrapper??.dep
WrapperJNI??.dep
WrapperJNI??.mak
.deps
*.ncb
*.suo
*.user
wrapper32_VC8__Win32_Debug
wrapper32_VC8__Win32_Release
decoderJNI_VC8__Win32_Debug
decoderJNI_VC8__Win32_Release
*.aps
wrapper32.vsprops
wrapper.vsprops
wrapper_VC8__Win32_Release
wrapper_VC8__x64_Debug
wrapper_VC8__x64_Release
wrapperJNI32_VC8__Win32_Release
wrapperJNI64_VC8__Win32_Release
wrapper64_VC8__Win32_Release
wrapper_VC8__Win32_Debug
Modified: trunk/wrapper/src/c/Makefile-windows-x86-32.nmake
===================================================================
--- trunk/wrapper/src/c/Makefile-windows-x86-32.nmake 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/Makefile-windows-x86-32.nmake 2007-04-02 07:30:44 UTC (rev 1316)
@@ -29,7 +29,7 @@
# EXE Definitions
EXE_OUTDIR = $(PROJ)32_VC8__Win32_Release
-EXE_OBJS = $(EXE_OUTDIR)\logger.obj $(EXE_OUTDIR)\property.obj $(EXE_OUTDIR)\wrapper.obj $(EXE_OUTDIR)\wrapper_win.obj $(EXE_OUTDIR)\wrappereventloop.obj $(EXE_OUTDIR)\wrapperinfo.obj
+EXE_OBJS = $(EXE_OUTDIR)\logger.obj $(EXE_OUTDIR)\property.obj $(EXE_OUTDIR)\wrapper.obj $(EXE_OUTDIR)\wrapper_win.obj $(EXE_OUTDIR)\wrappereventloop.obj $(EXE_OUTDIR)\wrapperinfo.obj
EXE_LIBS = wsock32.lib shlwapi.lib advapi32.lib user32.lib
EXE_COMPILE_OPTS = /O2 /GL /D "_CONSOLE" /Wp64
EXE_LINK_OPTS = /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /MANIFESTFILE:"$(EXE_OUTDIR)\$(PROJ).exe.intermediate.manifest" /PDB:"$(EXE_OUTDIR)\$(PROJ).pdb" /OPT:REF /OPT:ICF /OPT:WIN98 /LTCG
@@ -46,11 +46,6 @@
# Define project specific macros
-#BASE_OBJS =
-#EXTRA_LIBS = wsock32.lib shlwapi.lib advapi32.lib user32.lib
-#GLOBAL_DEP = logger.h property.h psapi.h wrapper.h wrapperinfo.h messages.h resource.h
-#RC_DEP = resource.h
-
#----- If OUTDIR does not exist, then create directory
$(EXE_OUTDIR) :
if not exist "$(EXE_OUTDIR)/$(NULL)" mkdir $(EXE_OUTDIR)
Deleted: trunk/wrapper/src/c/Makefile-windows-x86-64.nmake
===================================================================
--- trunk/wrapper/src/c/Makefile-windows-x86-64.nmake 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/Makefile-windows-x86-64.nmake 2007-04-02 07:30:44 UTC (rev 1316)
@@ -1,82 +0,0 @@
-# Copyright (c) 1999, 2007 Tanuki Software Inc.
-#
-# Permission is hereby granted, free of charge, to any person
-# obtaining a copy of the Java Service Wrapper and associated
-# documentation files (the "Software"), to deal in the Software
-# without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sub-license,
-# and/or sell copies of the Software, and to permit persons to
-# whom the Software is furnished to do so, subject to the
-# following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-# OTHER DEALINGS IN THE SOFTWARE.
-
-PROJ = wrapper
-
-COMPILE = cl /D "_AMD64_=1" /D "WIN64" /D "_WIN64" /D "WIN32" /FIPRE64PRA.H /D "NDEBUG" /FD /EHsc /MT /Zp8 /W3 /nologo /c /Zi /errorReport:prompt /D "_CRT_SECURE_NO_DEPRECATE"
-LINK = link /NOLOGO /MANIFEST /DEBUG /MACHINE:AMD64 /ERRORREPORT:PROMPT DelayImp.lib
-RC = rc
-
-# EXE Definitions
-EXE_OUTDIR = $(PROJ)64_VC8__Win32_Release
-EXE_OBJS = $(EXE_OUTDIR)\logger.obj $(EXE_OUTDIR)\property.obj $(EXE_OUTDIR)\wrapper.obj $(EXE_OUTDIR)\wrapper_win.obj $(EXE_OUTDIR)\wrappereventloop.obj $(EXE_OUTDIR)\wrapperinfo.obj
-EXE_LIBS = wsock32.lib shlwapi.lib advapi32.lib user32.lib bufferoverflowu.lib
-EXE_COMPILE_OPTS = /O2 /GL /D "_CONSOLE" /Wp64
-EXE_LINK_OPTS = /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /MANIFESTFILE:"$(EXE_OUTDIR)\$(PROJ).exe.intermediate.manifest" /PDB:"$(EXE_OUTDIR)\$(PROJ).pdb" /OPT:REF /OPT:ICF /OPT:WIN98 /LTCG
-
-# DLL Definitions
-DLL_OUTDIR = $(PROJ)JNI64_VC8__Win32_Release
-DLL_OBJS = $(DLL_OUTDIR)\wrapperjni.obj $(DLL_OUTDIR)\wrapperjni_win.obj $(DLL_OUTDIR)\wrapperinfo.obj
-DLL_LIBS = advapi32.lib user32.lib bufferoverflowu.lib
-DLL_COMPILE_OPTS = /Od /I "..\" /I ".\" /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WINDOWS" /D "_USRDLL" /D "DECODERJNI_VC8_EXPORTS" /D "_WINDLL"
-DLL_LINK_OPTS = /INCREMENTAL /DLL /SUBSYSTEM:WINDOWS /MANIFESTFILE:"$(DLL_OUTDIR)\$(PROJ).dll.intermediate.manifest" /PDB:"$(DLL_OUTDIR)\$(PROJ).pdb"
-
-
-all: $(EXE_OUTDIR) $(DLL_OUTDIR) $(PROJ).EXE $(PROJ).DLL
-
-# Define project specific macros
-
-#BASE_OBJS =
-#EXTRA_LIBS = wsock32.lib shlwapi.lib advapi32.lib user32.lib
-#GLOBAL_DEP = logger.h property.h psapi.h wrapper.h wrapperinfo.h messages.h resource.h
-#RC_DEP = resource.h
-
-#----- If OUTDIR does not exist, then create directory
-$(EXE_OUTDIR) :
- if not exist "$(EXE_OUTDIR)/$(NULL)" mkdir $(EXE_OUTDIR)
-$(DLL_OUTDIR) :
- if not exist "$(DLL_OUTDIR)/$(NULL)" mkdir $(DLL_OUTDIR)
-
-# Inference rule for updating the object files
-.c{$(EXE_OUTDIR)}.obj:
- $(COMPILE) $(EXE_COMPILE_OPTS) /Fo"$(EXE_OUTDIR)\\" /Fd"$(EXE_OUTDIR)\\" $**
-.c{$(DLL_OUTDIR)}.obj:
- $(COMPILE) $(DLL_COMPILE_OPTS) /Fo"$(DLL_OUTDIR)\\" /Fd"$(DLL_OUTDIR)\\" $**
-
-# Build rule for resource file
-$(EXE_OUTDIR)\$(PROJ).res: $(PROJ).rc $(RC_DEP)
- $(RC) /fo"$(EXE_OUTDIR)/$(PROJ).res" $(PROJ).rc
-$(DLL_OUTDIR)\$(PROJ).res: $(PROJ).rc $(RC_DEP)
- $(RC) /fo"$(DLL_OUTDIR)/$(PROJ).res" $(PROJ).rc
-
-$(PROJ).EXE: $(BASE_OBJS) $(EXE_OBJS) $(EXE_OUTDIR)\$(PROJ).res
- $(LINK) $(EXE_LINK_OPTS) $(EXE_OBJS) $(EXE_LIBS) $(EXE_OUTDIR)\$(PROJ).res /OUT:"..\..\bin\$(PROJ).exe"
-
-$(PROJ).DLL: $(BASE_OBJS) $(DLL_OBJS) $(DLL_OUTDIR)\$(PROJ).res
- $(LINK) $(DLL_LINK_OPTS) $(DLL_OBJS) $(DLL_LIBS) $(DLL_OUTDIR)\$(PROJ).res /OUT:"..\..\lib\$(PROJ).dll"
-
-clean:
- if exist $(EXE_OUTDIR)/$(NULL) rd /s /q $(EXE_OUTDIR)
- if exist $(DLL_OUTDIR)/$(NULL) rd /s /q $(DLL_OUTDIR)
- if exist ..\..\bin\$(PROJ).exe del /q ..\..\bin\$(PROJ).exe
- if exist ..\..\lib\$(PROJ).dll del /q ..\..\lib\$(PROJ).dll
Modified: trunk/wrapper/src/c/logger.c
===================================================================
--- trunk/wrapper/src/c/logger.c 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/logger.c 2007-04-02 07:30:44 UTC (rev 1316)
@@ -128,7 +128,7 @@
#ifdef WIN32
void writeToConsole( char *lpszFmt, ... );
#endif
-void checkAndRollLogs( );
+void checkAndRollLogs(const char *nowDate);
/* Any log messages generated within signal handlers must be stored until we
* have left the signal handler to avoid deadlocks in the logging code.
@@ -182,6 +182,11 @@
}
#endif
+void outOfMemory(const char *context, int id) {
+ log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, "Out of memory (%s%02d). %s",
+ context, id, getLastErrorText());
+}
+
/**
* Replaces one token with another. The length of the new token must be equal
* to or less than that of the old token.
@@ -391,12 +396,34 @@
free(currentLogFileName);
free(workLogFileName);
}
+ logFilePath = NULL;
+ currentLogFileName = NULL;
+ workLogFileName = NULL;
+
logFilePath = malloc(sizeof(char) * (len + 1));
+ if (!logFilePath) {
+ outOfMemory("SLP", 1);
+ return;
+ }
strcpy(logFilePath, log_file_path);
currentLogFileName = malloc(sizeof(char) * (len + 10 + 1));
+ if (!currentLogFileName) {
+ outOfMemory("SLP", 2);
+ free(logFilePath);
+ logFilePath = NULL;
+ return;
+ }
currentLogFileName[0] = '\0';
workLogFileName = malloc(sizeof(char) * (len + 10 + 1));
+ if (!workLogFileName) {
+ outOfMemory("SLP", 3);
+ free(logFilePath);
+ logFilePath = NULL;
+ free(currentLogFileName);
+ currentLogFileName = NULL;
+ return;
+ }
workLogFileName[0] = '\0';
#ifdef WIN32
@@ -445,8 +472,11 @@
if( max_file_size != NULL ) {
/* Allocate buffer */
- if( (tmpFileSizeBuff = (char *) malloc(sizeof(char) * (strlen( max_file_size ) + 1))) == NULL )
+ tmpFileSizeBuff = (char *) malloc(sizeof(char) * (strlen( max_file_size ) + 1));
+ if (!tmpFileSizeBuff) {
+ outOfMemory("SLMFS", 1);
return;
+ }
/* Generate multiple and remove unwanted chars */
multiple = 1;
@@ -521,7 +551,9 @@
break;
}
#else
- pthread_mutex_lock(&log_printfMutex);
+ if (pthread_mutex_lock(&log_printfMutex)) {
+ printf("Failed to lock the Logging mutex. %s\n", getLastErrorText());
+ }
#endif
return 0;
@@ -536,7 +568,9 @@
return -1;
}
#else
- pthread_mutex_unlock(&log_printfMutex);
+ if (pthread_mutex_unlock(&log_printfMutex)) {
+ printf("Failed to unlock the Logging mutex. %s\n", getLastErrorText());
+ }
#endif
return 0;
}
@@ -558,7 +592,9 @@
fclose(logfileFP);
logfileFP = NULL;
- currentLogFileName[0] = '\0';
+ if (currentLogFileName) {
+ currentLogFileName[0] = '\0';
+ }
}
/* Release the lock we have on this function so that other threads can get in. */
@@ -709,10 +745,20 @@
if ( threadPrintBuffer == NULL ) {
threadPrintBuffer = (char *)malloc( reqSize * sizeof( char ) );
+ if (!threadPrintBuffer) {
+ printf("Out of memory is logging code (BPB1)\n");
+ threadPrintBufferSize = 0;
+ return NULL;
+ }
threadPrintBufferSize = reqSize;
} else if ( threadPrintBufferSize < reqSize ) {
free( threadPrintBuffer );
threadPrintBuffer = (char *)malloc( reqSize * sizeof( char ) );
+ if (!threadPrintBuffer) {
+ printf("Out of memory is logging code (BPB2)\n");
+ threadPrintBufferSize = 0;
+ return NULL;
+ }
threadPrintBufferSize = reqSize;
}
@@ -907,20 +953,21 @@
if( level >= currentConsoleLevel ) {
/* Build up the printBuffer. */
printBuffer = buildPrintBuffer( source_id, level, threadId, queued, nowTM, nowMillis, consoleFormat, message );
-
- /* Write the print buffer to the console. */
+ if (printBuffer) {
+ /* Write the print buffer to the console. */
#ifdef WIN32
- if ( consoleStdoutHandle != NULL ) {
- writeToConsole( "%s\n", printBuffer );
- } else {
+ if ( consoleStdoutHandle != NULL ) {
+ writeToConsole( "%s\n", printBuffer );
+ } else {
#endif
- fprintf( stdout, "%s\n", printBuffer );
- if ( consoleFlush ) {
- fflush( stdout );
+ fprintf( stdout, "%s\n", printBuffer );
+ if ( consoleFlush ) {
+ fflush( stdout );
+ }
+#ifdef WIN32
}
-#ifdef WIN32
+#endif
}
-#endif
}
/* Logfile output by format */
@@ -928,7 +975,7 @@
/* Log the message to the log file */
if (level >= currentLogfileLevel) {
/* If the log file was set to a blank value then it will not be used. */
- if ( strlen( logFilePath ) > 0 )
+ if ( logFilePath && ( strlen( logFilePath ) > 0 ) )
{
/* If this the roll mode is date then we need a nowDate for this log entry. */
if (logFileRollMode & ROLL_MODE_DATE) {
@@ -976,26 +1023,27 @@
/* Build up the printBuffer. */
printBuffer = buildPrintBuffer( source_id, level, threadId, queued, nowTM, nowMillis, logfileFormat, message );
-
- fprintf( logfileFP, "%s\n", printBuffer );
-
- /* Increment the activity counter. */
- logfileActivityCount++;
-
- /* Only close the file if autoClose is set. Otherwise it will be closed later
- * after an appropriate period of inactivity. */
- if (autoCloseLogfile) {
+ if (printBuffer) {
+ fprintf( logfileFP, "%s\n", printBuffer );
+
+ /* Increment the activity counter. */
+ logfileActivityCount++;
+
+ /* Only close the file if autoClose is set. Otherwise it will be closed later
+ * after an appropriate period of inactivity. */
+ if (autoCloseLogfile) {
#ifdef _DEBUG
- printf("Closing logfile immediately...\n");
- fflush(NULL);
+ printf("Closing logfile immediately...\n");
+ fflush(NULL);
#endif
+
+ fclose(logfileFP);
+ logfileFP = NULL;
+ currentLogFileName[0] = '\0';
+ }
- fclose(logfileFP);
- logfileFP = NULL;
- currentLogFileName[0] = '\0';
+ /* Leave the file open. It will be closed later after a period of inactivity. */
}
-
- /* Leave the file open. It will be closed later after a period of inactivity. */
}
}
}
@@ -1040,6 +1088,11 @@
/* No buffer yet. Allocate one to get started. */
threadMessageBufferSize = 100;
threadMessageBuffer = (char*)malloc( threadMessageBufferSize * sizeof(char) );
+ if (!threadMessageBuffer) {
+ printf("Out of memory is logging code (P1)\n");
+ threadMessageBufferSize = 0;
+ return;
+ }
}
/* Try writing to the buffer. */
@@ -1074,6 +1127,11 @@
}
threadMessageBuffer = (char*)malloc( threadMessageBufferSize * sizeof(char) );
+ if (!threadMessageBuffer) {
+ printf("Out of memory is logging code (P2)\n");
+ threadMessageBufferSize = 0;
+ return;
+ }
/* Always set the count to -1 so we will loop again. */
count = -1;
@@ -1209,12 +1267,18 @@
void sendEventlogMessage( int source_id, int level, const char *szBuff ) {
#ifdef WIN32
char header[16];
- const char **strings = (char **) malloc( 3 * sizeof( char * ) );
+ const char **strings;
WORD eventType;
HANDLE handle;
WORD eventID, categoryID;
int result;
+ strings = (char **) malloc( 3 * sizeof( char * ) );
+ if (!strings) {
+ printf("Out of memory is logging code (SEM1)\n");
+ return;
+ }
+
/* Build the source header */
switch( source_id ) {
case WRAPPER_SOURCE_WRAPPER:
@@ -1388,6 +1452,10 @@
if ( vWriteToConsoleBuffer == NULL ) {
vWriteToConsoleBuffer = (char *)malloc( vWriteToConsoleBufferSize * sizeof(char) );
+ if (!vWriteToConsoleBuffer) {
+ printf("Out of memory is logging code (WTC1)\n");
+ return;
+ }
}
/* The only way I could figure out how to write to the console
@@ -1408,6 +1476,10 @@
free( vWriteToConsoleBuffer );
vWriteToConsoleBufferSize += 100;
vWriteToConsoleBuffer = (char *)malloc( vWriteToConsoleBufferSize * sizeof(char) );
+ if (!vWriteToConsoleBuffer) {
+ printf("Out of memory is logging code (WTC2)\n");
+ return;
+ }
}
/* We can now write the message. */
@@ -1430,6 +1502,10 @@
char rollNum[11];
struct stat fileStat;
int result;
+
+ if (!logFilePath) {
+ return;
+ }
/* If the log file is currently open, it needs to be closed. */
if (logfileFP != NULL) {
@@ -1561,6 +1637,10 @@
fflush(NULL);
#endif
latestFiles[i] = malloc(sizeof(char) * (strlen(testFile) + 1));
+ if (!latestFiles[i]) {
+ printf("Out of memory is logging code (LLFCHF1)\n");
+ return;
+ }
strcpy(latestFiles[i], testFile);
return;
} else {
@@ -1602,6 +1682,10 @@
fflush(NULL);
#endif
latestFiles[i] = malloc(sizeof(char) * (strlen(testFile) + 1));
+ if (!latestFiles[i]) {
+ printf("Out of memory is logging code (LLFCHF2)\n");
+ return;
+ }
strcpy(latestFiles[i], testFile);
return;
}
@@ -1643,16 +1727,28 @@
#endif
latestFiles = malloc(sizeof(char *) * count);
+ if (!latestFiles) {
+ printf("Out of memory is logging code (LLFC1)\n");
+ return;
+ }
for (i = 0; i < count; i++) {
latestFiles[i] = NULL;
}
/* Set the first element to the current file so things will work correctly if it already
* exists. */
latestFiles[0] = malloc(sizeof(char) * (strlen(current) + 1));
+ if (!latestFiles[0]) {
+ printf("Out of memory is logging code (LLFC2)\n");
+ return;
+ }
strcpy(latestFiles[0], current);
#ifdef WIN32
path = malloc(sizeof(char) * (strlen(pattern) + 1));
+ if (!path) {
+ printf("Out of memory is logging code (LLFC3)\n");
+ return;
+ }
/* Extract any path information from the beginning of the file */
strcpy(path, pattern);
@@ -1673,6 +1769,10 @@
}
} else {
testFile = malloc(sizeof(char) * (strlen(path) + strlen(fblock.name) + 1));
+ if (!testFile) {
+ printf("Out of memory is logging code (LLFC4)\n");
+ return;
+ }
sprintf(testFile, "%s%s", path, fblock.name);
limitLogFileCountHandleFile(current, testFile, latestFiles, count);
free(testFile);
@@ -1681,6 +1781,10 @@
/* Look for additional entries */
while (_findnext(handle, &fblock) == 0) {
testFile = malloc(sizeof(char) * (strlen(path) + strlen(fblock.name) + 1));
+ if (!testFile) {
+ printf("Out of memory is logging code (LLFC5)\n");
+ return;
+ }
sprintf(testFile, "%s%s", path, fblock.name);
limitLogFileCountHandleFile(current, testFile, latestFiles, count);
free(testFile);
@@ -1868,6 +1972,10 @@
* efficient than necessary. */
do {
buffer = malloc( sizeof( char ) * bufferSize );
+ if (!buffer) {
+ printf("Out of memory is logging code (PQ1)\n");
+ return;
+ }
/* Before we can store the string, we need to know how much space is required to do so. */
va_start( vargs, lpszFmt );
@@ -1986,3 +2094,4 @@
}
}
}
+
Modified: trunk/wrapper/src/c/logger.h
===================================================================
--- trunk/wrapper/src/c/logger.h 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/logger.h 2007-04-02 07:30:44 UTC (rev 1316)
@@ -127,6 +127,8 @@
#define strcmpIgnoreCase(str1, str2) strcasecmp(str1, str2)
#endif
+extern void outOfMemory(const char *context, int id);
+
/* * Logfile functions * */
extern void setLogfilePath( const char *log_file_path );
extern int getLogfileRollModeForName( const char *logfileRollName );
Deleted: trunk/wrapper/src/c/makewin64.bat
===================================================================
--- trunk/wrapper/src/c/makewin64.bat 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/makewin64.bat 2007-04-02 07:30:44 UTC (rev 1316)
@@ -1,15 +0,0 @@
-@... off
-echo Building C Targets
-REM call VCVARSnn.BAT
-call %1
-
-NMAKE.EXE -f Wrapper64.mak CFG="Wrapper - Win64 Release" ALL
-if not errorlevel 1 goto ok1
-exit %ERRORLEVEL%
-
-:ok1
-NMAKE.EXE -f WrapperJNI64.mak CFG="WrapperJNI - Win64 Release" ALL
-if not errorlevel 1 goto end
-exit %ERRORLEVEL%
-
-:end
Modified: trunk/wrapper/src/c/property.c
===================================================================
--- trunk/wrapper/src/c/property.c 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/property.c 2007-04-02 07:30:44 UTC (rev 1316)
@@ -95,9 +95,13 @@
printf( "Unreplaced property %s=%s\n", property->name, property->value );
#endif
oldValue = malloc(strlen(property->value) + 1);
- strcpy(oldValue, property->value);
- setInnerProperty(property, oldValue);
- free(oldValue);
+ if (!oldValue) {
+ outOfMemory("GIP", 1);
+ } else {
+ strcpy(oldValue, property->value);
+ setInnerProperty(property, oldValue);
+ free(oldValue);
+ }
#ifdef _DEBUG
printf( " -> property %s=%s\n", property->name, property->value );
#endif
@@ -157,6 +161,10 @@
Property *property;
property = malloc(sizeof(Property));
+ if (!property) {
+ outOfMemory("CIP", 1);
+ return NULL;
+ }
property->name = NULL;
property->next = NULL;
property->previous = NULL;
@@ -324,23 +332,26 @@
evaluateEnvironmentVariables(propertyValue, buffer, MAX_PROPERTY_VALUE_LENGTH);
property->value = malloc(sizeof(char) * (strlen(buffer) + 1));
-
- /* Strip any non valid characters like control characters. Some valid characters are
- * less than 0 when the char is unsigned. */
- for (i = 0, count = 0; i < (int)strlen(buffer); i++) {
- /* Only add valid chars, skip control chars. We want all chars other than those
- * in the range 1..31. 0 is not possible as that would be end of the string.
- * On most platforms, char is signed, but on PowerPC, it is unsigned. This
- * means that any comparison such as >= 0 will cause a compiler error as that
- * would always be true.
- * The logic below is to get the correct behavior in either case assuming no 0. */
- if ((buffer[i] < 1) || (buffer[i] > 31)) {
- property->value[count++] = buffer[i];
+ if (!property->value) {
+ outOfMemory("SIP", 1);
+ } else {
+ /* Strip any non valid characters like control characters. Some valid characters are
+ * less than 0 when the char is unsigned. */
+ for (i = 0, count = 0; i < (int)strlen(buffer); i++) {
+ /* Only add valid chars, skip control chars. We want all chars other than those
+ * in the range 1..31. 0 is not possible as that would be end of the string.
+ * On most platforms, char is signed, but on PowerPC, it is unsigned. This
+ * means that any comparison such as >= 0 will cause a compiler error as that
+ * would always be true.
+ * The logic below is to get the correct behavior in either case assuming no 0. */
+ if ((buffer[i] < 1) || (buffer[i] > 31)) {
+ property->value[count++] = buffer[i];
+ }
}
+
+ /* Crop string to new size */
+ property->value[count] = '\0';
}
-
- /* Crop string to new size */
- property->value[count] = '\0';
}
}
@@ -480,6 +491,10 @@
Properties* createProperties() {
Properties *properties = malloc(sizeof(Properties));
+ if (!properties) {
+ outOfMemory("CP", 1);
+ return NULL;
+ }
properties->first = NULL;
properties->last = NULL;
return properties;
@@ -548,9 +563,13 @@
* this memory so it is not freed after we set it. We only call this on
* startup, so the leak is minor. */
envBuf = malloc(sizeof(char) * (strlen(name) + strlen(value) + 2));
- sprintf(envBuf, "%s=%s", name, value);
- if (putenv(envBuf)) {
- printf("Unable to set environment variable: %s\n", envBuf);
+ if (!envBuf) {
+ outOfMemory("SE", 1);
+ } else {
+ sprintf(envBuf, "%s=%s", name, value);
+ if (putenv(envBuf)) {
+ printf("Unable to set environment variable: %s\n", envBuf);
+ }
}
}
@@ -597,8 +616,16 @@
/* It is possible that the propertyName and or properyValue contains extra spaces. */
propertyNameTrim = malloc(sizeof(char) * (strlen(propertyName) + 1));
+ if (!propertyNameTrim) {
+ outOfMemory("AP", 1);
+ return;
+ }
trim(propertyName, propertyNameTrim);
propertyValueTrim = malloc(sizeof(char) * (strlen(propertyValue) + 1));
+ if (!propertyValueTrim) {
+ outOfMemory("AP", 2);
+ return;
+ }
trim(propertyValue, propertyValueTrim);
#ifdef _DEBUG
@@ -612,9 +639,16 @@
if (property == NULL) {
/* This is a new property */
property = createInnerProperty();
+ if (!property) {
+ return;
+ }
/* Store a copy of the name */
property->name = malloc(sizeof(char) * (strlen(propertyNameTrim) + 1));
+ if (!property->name) {
+ outOfMemory("AP", 3);
+ return;
+ }
strcpy(property->name, propertyNameTrim);
/* Insert this property at the correct location. */
@@ -830,6 +864,10 @@
/* Now that we know how much space this will all take up, allocate a buffer. */
fullBuffer = buffer = malloc(size);
+ if (!fullBuffer) {
+ outOfMemory("LP", 1);
+ return NULL;
+ }
/* Now actually build up the output. Any separator characters need to be escaped with themselves. */
property = properties->first;
Modified: trunk/wrapper/src/c/wrapper.c
===================================================================
--- trunk/wrapper/src/c/wrapper.c 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapper.c 2007-04-02 07:30:44 UTC (rev 1316)
@@ -173,6 +173,10 @@
return 1;
}
wrapperData->configFile = malloc(sizeof(char) * work);
+ if (!wrapperData->configFile) {
+ outOfMemory("WLCP", 1);
+ return 1;
+ }
if (!GetFullPathName(wrapperData->argConfFile, work, wrapperData->configFile, &filePart)) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL,
"Unable to resolve the full path of the configuration file, %s: %s",
@@ -184,6 +188,10 @@
* path is provided. We always need an abosulte path here. So build up one and
* then use realpath to remove any .. or other relative references. */
wrapperData->configFile = malloc(PATH_MAX);
+ if (!wrapperData->configFile) {
+ outOfMemory("WLCP", 2);
+ return 1;
+ }
if (realpath(wrapperData->argConfFile, wrapperData->configFile) == NULL) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL,
"Unable to resolve the full path of the configuration file, %s: %s",
@@ -201,6 +209,10 @@
return 1;
}
wrapperData->originalWorkingDir = malloc(sizeof(char) * work);
+ if (!wrapperData->originalWorkingDir) {
+ outOfMemory("WLCP", 3);
+ return 1;
+ }
if (!GetFullPathName(".", work, wrapperData->originalWorkingDir, &filePart)) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL,
"Unable to resolve the original working directory: %s", getLastErrorText());
@@ -211,6 +223,10 @@
* path is provided. We always need an abosulte path here. So build up one and
* then use realpath to remove any .. or other relative references. */
wrapperData->originalWorkingDir = malloc(PATH_MAX);
+ if (!wrapperData->originalWorkingDir) {
+ outOfMemory("WLCP", 4);
+ return 1;
+ }
if (realpath(".", wrapperData->originalWorkingDir) == NULL) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL,
"Unable to resolve the original working directory: %s", getLastErrorText());
@@ -221,6 +237,9 @@
/* Create a Properties structure. */
properties = createProperties();
+ if (!properties) {
+ return 1;
+ }
wrapperAddDefaultProperties();
/* The argument prior to the argBase will be the configuration file, followed
@@ -277,6 +296,10 @@
return 1;
}
wrapperData->workingDir = malloc(sizeof(char) * work);
+ if (!wrapperData->workingDir) {
+ outOfMemory("WLCP", 5);
+ return 1;
+ }
if (!GetFullPathName(prop, work, wrapperData->workingDir, &filePart)) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL,
"Unable to resolve the working directory %s: %s", prop, getLastErrorText());
@@ -287,6 +310,10 @@
* path is provided. We always need an abosulte path here. So build up one and
* then use realpath to remove any .. or other relative references. */
wrapperData->workingDir = malloc(PATH_MAX);
+ if (!wrapperData->workingDir) {
+ outOfMemory("WLCP", 6);
+ return 1;
+ }
if (realpath(prop, wrapperData->workingDir) == NULL) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL,
"Unable to resolve the working directory %s: %s", prop, getLastErrorText());
@@ -737,6 +764,10 @@
free(protocolSendBuffer);
}
protocolSendBuffer = malloc(len);
+ if (!protocolSendBuffer) {
+ outOfMemory("WPF", 1);
+ return -1;
+ }
}
if (sd == INVALID_SOCKET) {
@@ -978,6 +1009,10 @@
* set below, but this extra step will protect against future changes. Some
* platforms appear to initialize maloc'd memory to 0 while others do not. */
wrapperData = malloc(sizeof(WrapperConfig));
+ if (!wrapperData) {
+ outOfMemory("WI", 1);
+ return 1;
+ }
memset(wrapperData, 0, sizeof(WrapperConfig));
/* Setup the initial values of required properties. */
wrapperData->configured = FALSE;
@@ -1039,12 +1074,14 @@
/**
* Returns the file name base as a newly malloced char *. The resulting
* base file name will have any path and extension stripped.
+ *
+ * baseName should be long enough to always contain the base name.
+ * (strlen(fileName) + 1) is safe.
*/
-char *wrapperGetFileBase(const char *fileName) {
+void wrapperGetFileBase(const char *fileName, char *baseName) {
const char *start;
const char *end;
const char *c;
- char *base;
start = fileName;
end = &fileName[strlen(fileName)];
@@ -1066,26 +1103,32 @@
}
/* Now create the new base name. */
- base = malloc((end - start + 1) * sizeof(char));
- memcpy(base, start, end - start);
- base[end - start] = '\0';
-
- return base;
+ memcpy(baseName, start, end - start);
+ baseName[end - start] = '\0';
}
/**
* Output the version.
*/
void wrapperVersionBanner() {
- printf("Wrapper (Version %s) http://wrapper.tanukisoftware.org\n", wrapperVersion);
+ printf("Wrapper Community Edition (Version %s)\n", wrapperVersion);
+ printf(" Copyright 1999, 2007 Tanuki Software, Inc. All Rights Reserved.\n");
+ printf(" http://wrapper.tanukisoftware.org\n");
}
/**
* Output the application usage.
*/
void wrapperUsage(char *appName) {
- char *confFileBase = wrapperGetFileBase(appName);
+ char *confFileBase;
+ confFileBase = malloc(strlen(appName) + 1);
+ if (!confFileBase) {
+ outOfMemory("WU", 1);
+ return;
+ }
+ wrapperGetFileBase(appName, confFileBase);
+
wrapperVersionBanner();
printf("\n");
printf("Usage:\n");
@@ -1122,6 +1165,8 @@
printf(" in wrapper.conf. For example:\n");
printf(" wrapper.debug=true\n");
printf("\n");
+
+ free(confFileBase);
}
/**
@@ -1152,12 +1197,25 @@
} else {
/* Syntax 3 */
/* Only a command was specified. Assume a default config file name. */
- argConfFileBase = wrapperGetFileBase(argv[0]);
- wrapperData->argConfFile = malloc((strlen(argConfFileBase) + 4 + 1) * sizeof(char));
+ argConfFileBase = malloc(strlen(argv[0]) + 1);
+ if (!argConfFileBase) {
+ outOfMemory("WPA", 1);
+ return FALSE;
+ }
+ wrapperGetFileBase(argv[0], argConfFileBase);
+
+ /* The following malloc is only called once, but is never freed. */
+ wrapperData->argConfFile = malloc((strlen(argConfFileBase) + 5 + 1) * sizeof(char));
+ if (!wrapperData->argConfFile) {
+ outOfMemory("WPA", 2);
+ free(argConfFileBase);
+ return FALSE;
+ }
sprintf(wrapperData->argConfFile, "%s.conf", argConfFileBase);
wrapperData->argConfFileDefault = TRUE;
wrapperData->argCount = argc - 2;
wrapperData->argValues = &argv[2];
+ free(argConfFileBase);
}
} else {
/* Syntax 2 */
@@ -1172,12 +1230,25 @@
/* A config file was not specified. Assume a default config file name. */
wrapperData->argCommand = "c";
- argConfFileBase = wrapperGetFileBase(argv[0]);
- wrapperData->argConfFile = malloc((strlen(argConfFileBase) + 4 + 1) * sizeof(char));
+ argConfFileBase = malloc(strlen(argv[0]) + 1);
+ if (!argConfFileBase) {
+ outOfMemory("WPA", 3);
+ return FALSE;
+ }
+ wrapperGetFileBase(argv[0], argConfFileBase);
+
+ /* The following malloc is only called once, but is never freed. */
+ wrapperData->argConfFile = malloc((strlen(argConfFileBase) + 5 + 1) * sizeof(char));
+ if (!wrapperData->argConfFile) {
+ outOfMemory("WPA", 4);
+ free(argConfFileBase);
+ return FALSE;
+ }
sprintf(wrapperData->argConfFile, "%s.conf", argConfFileBase);
wrapperData->argConfFileDefault = TRUE;
wrapperData->argCount = argc - 1;
wrapperData->argValues = &argv[1];
+ free(argConfFileBase);
}
return TRUE;
@@ -1228,9 +1299,11 @@
char *buffer;
buffer = linearizeProperties(properties, '\t');
- wrapperProtocolFunction(FALSE, WRAPPER_MSG_PROPERTIES, buffer);
-
- free(buffer);
+ if (buffer) {
+ wrapperProtocolFunction(FALSE, WRAPPER_MSG_PROPERTIES, buffer);
+
+ free(buffer);
+ }
}
/**
@@ -1571,7 +1644,7 @@
char paramBuffer2[128];
int quotable;
int i, j;
- size_t len2;
+ size_t len, len2;
size_t cpLen, cpLenAlloc;
char *tmpString;
struct stat statBuffer;
@@ -1580,7 +1653,6 @@
#ifdef WIN32
char cpPath[512];
intptr_t handle;
- size_t len;
int found;
struct _finddata_t fblock;
#else
@@ -1652,6 +1724,10 @@
if (found) {
strings[index] = malloc(sizeof(char) * (strlen(cpPath) + 2 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 1);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "\"%s\"", cpPath);
} else {
@@ -1659,6 +1735,10 @@
}
} else {
strings[index] = malloc(sizeof(char) * (strlen(prop) + 2 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 2);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "\"%s\"", prop);
} else {
@@ -1673,6 +1753,10 @@
#else /* UNIX */
strings[index] = malloc(sizeof(char) * (strlen(prop) + 2 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 3);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "\"%s\"", prop);
} else {
@@ -1708,6 +1792,10 @@
"The value of property '%s', '%s' is not a valid argument to the jvm. Skipping.",
paramBuffer, prop );
strings[index] = malloc(sizeof(char) * 1);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 4);
+ return -1;
+ }
strings[index][0] = '\0';
} else {
quotable = isQuotableProperty(properties, paramBuffer);
@@ -1719,6 +1807,10 @@
}
if (stripQuote) {
propStripped = malloc(sizeof(char) * (strlen(prop) + 1));
+ if (!propStripped) {
+ outOfMemory("WBJCAI", 5);
+ return -1;
+ }
wrapperStripQuotes(prop, propStripped);
} else {
propStripped = (char *)prop;
@@ -1727,9 +1819,17 @@
if (addQuotes && quotable && strchr(propStripped, ' ')) {
len = quoteValue(propStripped, NULL, 0);
strings[index] = malloc(len);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 6);
+ return -1;
+ }
quoteValue(propStripped, strings[index], len);
} else {
strings[index] = malloc(sizeof(char) * (strlen(propStripped) + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 7);
+ return -1;
+ }
sprintf(strings[index], "%s", propStripped);
}
@@ -1760,6 +1860,10 @@
initMemory = __max(initMemory, 1); /* 1 <= n */
if (strings) {
strings[index] = malloc(sizeof(char) * (5 + 4 + 1)); /* Allow up to 4 digits. */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 8);
+ return -1;
+ }
sprintf(strings[index], "-Xms%dm", initMemory);
}
index++;
@@ -1774,6 +1878,10 @@
maxMemory = __max(maxMemory, initMemory); /* initMemory <= n */
if (strings) {
strings[index] = malloc(sizeof(char) * (5 + 4 + 1)); /* Allow up to 4 digits. */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 9);
+ return -1;
+ }
sprintf(strings[index], "-Xmx%dm", maxMemory);
}
index++;
@@ -1818,6 +1926,10 @@
* before the quote. */
if (systemPath) {
strings[index] = malloc(sizeof(char) * (22 + strlen(prop) + 1 + strlen(systemPath) + 1 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 10);
+ return -1;
+ }
if (addQuotes) {
if ((strlen(systemPath) > 1) && (systemPath[strlen(systemPath) - 1] == '\\')) {
sprintf(strings[index], "-Djava.library.path=\"%s%c%s\\\"", prop, wrapperClasspathSeparator, systemPath);
@@ -1829,6 +1941,10 @@
}
} else {
strings[index] = malloc(sizeof(char) * (22 + strlen(prop) + 1 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 11);
+ return -1;
+ }
if (addQuotes) {
if ((strlen(prop) > 1) && (prop[strlen(prop) - 1] == '\\')) {
sprintf(strings[index], "-Djava.library.path=\"%s\\\"", prop);
@@ -1848,6 +1964,10 @@
cpLen = 0;
cpLenAlloc = 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 12);
+ return -1;
+ }
/* Start with the property value. */
sprintf(&(strings[index][cpLen]), "-Djava.library.path=");
@@ -1874,6 +1994,10 @@
tmpString = strings[index];
cpLenAlloc += 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 13);
+ return -1;
+ }
sprintf(strings[index], "%s", tmpString);
free(tmpString);
tmpString = NULL;
@@ -1900,6 +2024,10 @@
tmpString = strings[index];
cpLenAlloc += 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 14);
+ return -1;
+ }
sprintf(strings[index], "%s", tmpString);
free(tmpString);
tmpString = NULL;
@@ -1941,6 +2069,10 @@
/* Store the classpath */
if (strings) {
strings[index] = malloc(sizeof(char) * (10 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 15);
+ return -1;
+ }
sprintf(strings[index], "-classpath");
}
index++;
@@ -1949,6 +2081,10 @@
cpLen = 0;
cpLenAlloc = 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 16);
+ return -1;
+ }
/* Add an open quote the classpath */
if (addQuotes) {
@@ -1997,6 +2133,10 @@
tmpString = strings[index];
cpLenAlloc += 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 17);
+ return -1;
+ }
sprintf(strings[index], "%s", tmpString);
free(tmpString);
tmpString = NULL;
@@ -2019,6 +2159,10 @@
tmpString = strings[index];
cpLenAlloc += 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 18);
+ return -1;
+ }
sprintf(strings[index], "%s", tmpString);
free(tmpString);
tmpString = NULL;
@@ -2049,6 +2193,10 @@
tmpString = strings[index];
cpLenAlloc += 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 19);
+ return -1;
+ }
sprintf(strings[index], "%s", tmpString);
free(tmpString);
tmpString = NULL;
@@ -2075,6 +2223,10 @@
propStripped = (char *)prop;
if ((prop[strlen(prop) - 1] == '/') || (prop[strlen(prop) - 1] == '\\')) {
propStripped = malloc(sizeof(char) * strlen(prop));
+ if (!propStripped) {
+ outOfMemory("WBJCAI", 20);
+ return -1;
+ }
memcpy(propStripped, prop, strlen(prop) - 1);
propStripped[strlen(prop) - 1] = '\0';
}
@@ -2106,6 +2258,10 @@
tmpString = strings[index];
cpLenAlloc += 1024;
strings[index] = malloc(sizeof(char) * cpLenAlloc);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 21);
+ return -1;
+ }
sprintf(strings[index], "%s", tmpString);
free(tmpString);
tmpString = NULL;
@@ -2149,6 +2305,10 @@
if (strings) {
wrapperBuildKey();
strings[index] = malloc(sizeof(char) * (16 + strlen(wrapperData->key) + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 22);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.key=\"%s\"", wrapperData->key);
} else {
@@ -2160,6 +2320,10 @@
/* Store the Wrapper server port */
if (strings) {
strings[index] = malloc(sizeof(char) * (15 + 5 + 1)); /* Port up to 5 characters */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 23);
+ return -1;
+ }
sprintf(strings[index], "-Dwrapper.port=%d", (int)wrapperData->actualPort);
}
index++;
@@ -2169,17 +2333,29 @@
{
if (strings) {
strings[index] = malloc(sizeof(char) * (19 + 5 + 1)); /* Port up to 5 characters */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 24);
+ return -1;
+ }
sprintf(strings[index], "-Dwrapper.jvm.port=%d", (int)wrapperData->jvmPort);
}
index++;
}
if (strings) {
strings[index] = malloc(sizeof(char) * (23 + 5 + 1)); /* Port up to 5 characters */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 25);
+ return -1;
+ }
sprintf(strings[index], "-Dwrapper.jvm.port.min=%d", (int)wrapperData->jvmPortMin);
}
index++;
if (strings) {
strings[index] = malloc(sizeof(char) * (23 + 5 + 1)); /* Port up to 5 characters */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 26);
+ return -1;
+ }
sprintf(strings[index], "-Dwrapper.jvm.port.max=%d", (int)wrapperData->jvmPortMax);
}
index++;
@@ -2188,6 +2364,10 @@
if (wrapperData->isDebugging) {
if (strings) {
strings[index] = malloc(sizeof(char) * (22 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 27);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.debug=\"TRUE\"");
} else {
@@ -2200,6 +2380,10 @@
/* Store the Wrapper PID */
if (strings) {
strings[index] = malloc(sizeof(char) * (24 + 1)); /* Pid up to 10 characters */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 28);
+ return -1;
+ }
sprintf(strings[index], "-Dwrapper.pid=%d", wrapperGetPID());
}
index++;
@@ -2208,6 +2392,10 @@
if (wrapperData->useSystemTime ) {
if (strings) {
strings[index] = malloc(sizeof(char) * (32 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 29);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.use_system_time=\"TRUE\"");
} else {
@@ -2221,6 +2409,10 @@
if (wrapperData->timerFastThreshold != WRAPPER_TIMER_FAST_THRESHOLD) {
if (strings) {
strings[index] = malloc(sizeof(char) * (43 + 1)); /* Allow for 10 digits */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 30);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.timer_fast_threshold=\"%d\"", wrapperData->timerFastThreshold * WRAPPER_TICK_MS / 1000);
} else {
@@ -2232,6 +2424,10 @@
if (wrapperData->timerSlowThreshold != WRAPPER_TIMER_SLOW_THRESHOLD) {
if (strings) {
strings[index] = malloc(sizeof(char) * (43 + 1)); /* Allow for 10 digits */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 31);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.timer_slow_threshold=\"%d\"", wrapperData->timerSlowThreshold * WRAPPER_TICK_MS / 1000);
} else {
@@ -2246,6 +2442,10 @@
* WrapperManager class uses it to verify that the version matches. */
if (strings) {
strings[index] = malloc(sizeof(char) * (20 + strlen(wrapperVersion) + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 32);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.version=\"%s\"", wrapperVersion);
} else {
@@ -2257,6 +2457,10 @@
/* Store the base name of the native library. */
if (strings) {
strings[index] = malloc(sizeof(char) * (27 + strlen(wrapperData->nativeLibrary) + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 33);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.native_library=\"%s\"", wrapperData->nativeLibrary);
} else {
@@ -2269,6 +2473,10 @@
if (wrapperData->ignoreSignals) {
if (strings) {
strings[index] = malloc(sizeof(char) * (31 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 34);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.ignore_signals=\"TRUE\"");
} else {
@@ -2286,6 +2494,10 @@
#endif
if (strings) {
strings[index] = malloc(sizeof(char) * (24 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 35);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.service=\"TRUE\"");
} else {
@@ -2299,6 +2511,10 @@
if (wrapperData->isShutdownHookDisabled) {
if (strings) {
strings[index] = malloc(sizeof(char) * (38 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 36);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.disable_shutdown_hook=\"TRUE\"");
} else {
@@ -2312,6 +2528,10 @@
if (strings) {
/* Just to be safe, allow 20 characters for the timeout value */
strings[index] = malloc(sizeof(char) * (24 + 20 + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 37);
+ return -1;
+ }
if (addQuotes) {
sprintf(strings[index], "-Dwrapper.cpu.timeout=\"%d\"", wrapperData->cpuTimeout);
} else {
@@ -2323,6 +2543,10 @@
/* Store the Wrapper JVM ID. (Get here before incremented) */
if (strings) {
strings[index] = malloc(sizeof(char) * (16 + 5 + 1)); /* jvmid up to 5 characters */
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 38);
+ return -1;
+ }
sprintf(strings[index], "-Dwrapper.jvmid=%d", (wrapperData->jvmRestarts + 1));
}
index++;
@@ -2331,6 +2555,10 @@
if (strings) {
prop = getStringProperty(properties, "wrapper.java.mainclass", "Main");
strings[index] = malloc(sizeof(char) * (strlen(prop) + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 39);
+ return -1;
+ }
sprintf(strings[index], "%s", prop);
}
index++;
@@ -2352,6 +2580,10 @@
}
if (stripQuote) {
propStripped = malloc(sizeof(char) * (strlen(prop) + 1));
+ if (!propStripped) {
+ outOfMemory("WBJCAI", 40);
+ return -1;
+ }
wrapperStripQuotes(prop, propStripped);
} else {
propStripped = (char *)prop;
@@ -2360,9 +2592,17 @@
if (addQuotes && quotable && strchr(propStripped, ' ')) {
len = quoteValue(propStripped, NULL, 0);
strings[index] = malloc(len);
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 41);
+ return -1;
+ }
quoteValue(propStripped, strings[index], len);
} else {
strings[index] = malloc(sizeof(char) * (strlen(propStripped) + 1));
+ if (!strings[index]) {
+ outOfMemory("WBJCAI", 42);
+ return -1;
+ }
sprintf(strings[index], "%s", propStripped);
}
@@ -2406,6 +2646,10 @@
/* Allocate the correct amount of memory */
*stringsPtr = malloc(sizeof(char *) * (*length));
+ if (!stringsPtr) {
+ outOfMemory("WBJCA", 1);
+ return TRUE;
+ }
/* Now actually fill in the strings */
reqLen = wrapperBuildJavaCommandArrayInner(*stringsPtr, addQuotes);
@@ -2591,7 +2835,12 @@
if (value != NULL) {
*ptr = malloc(sizeof(char) * (strlen(value) + 1));
- strcpy(*ptr, value);
+ if (!ptr) {
+ outOfMemory("USV", 1);
+ /* TODO: This is pretty bad. Not sure how to recover... */
+ } else {
+ strcpy(*ptr, value);
+ }
}
}
@@ -2605,7 +2854,10 @@
#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000
#endif
-void wrapperBuildNTServiceInfo() {
+/**
+ * Return FALSE if successful, TRUE if there were problems.
+ */
+int wrapperBuildNTServiceInfo() {
char dependencyKey[32]; /* Length of "wrapper.ntservice.dependency.nn" + '\0' */
const char *dependencies[10];
char *work;
@@ -2650,6 +2902,10 @@
wrapperData->ntServiceDependencies = NULL;
}
work = wrapperData->ntServiceDependencies = malloc(sizeof(char) * len);
+ if (!work) {
+ outOfMemory("WBNTSI", 1);
+ return TRUE;
+ }
for (i = 0; i < 10; i++) {
if (dependencies[i] != NULL) {
strcpy(work, dependencies[i]);
@@ -2736,6 +2992,8 @@
/* Set the single invocation flag. */
wrapperData->isSingleInvocation = getBooleanProperty( properties, "wrapper.single_invocation", FALSE );
+
+ return FALSE;
}
#endif
@@ -2758,7 +3016,10 @@
}
}
-void wrapperBuildUnixDaemonInfo() {
+/**
+ * Return FALSE if successful, TRUE if there were problems.
+ */
+int wrapperBuildUnixDaemonInfo() {
if (!wrapperData->configured) {
/** Get the daemonize flag. */
wrapperData->daemonize = getBooleanProperty(properties, "wrapper.daemonize", FALSE);
@@ -2772,6 +3033,8 @@
/** Configure the USR2 signal handler. */
wrapperData->signalUSR2Mode = getSignalMode(getStringProperty(properties, "wrapper.signal.mode.usr2", NULL), WRAPPER_SIGNAL_MODE_FORWARD);
}
+
+ return FALSE;
}
#endif
@@ -2798,6 +3061,9 @@
}
}
+/**
+ * Return FALSE if successful, TRUE if there were problems.
+ */
int loadConfiguration() {
const char* logfilePath;
int logfileRollMode;
@@ -3097,12 +3363,24 @@
/* Now that a count is known, allocate memory to hold the filters and actions and load them in. */
if (wrapperData->outputFilterCount > 0) {
wrapperData->outputFilters = malloc(sizeof(char *) * wrapperData->outputFilterCount);
+ if (!wrapperData->outputFilters) {
+ outOfMemory("LC", 1);
+ return TRUE;
+ }
wrapperData->outputFilterActions = malloc(sizeof(int) * wrapperData->outputFilterCount);
+ if (!wrapperData->outputFilterActions) {
+ outOfMemory("LC", 2);
+ return TRUE;
+ }
for (i = 0; i < wrapperData->outputFilterCount; i++) {
/* Get the filter */
sprintf(key, "wrapper.filter.trigger.%d", i + 1);
val = getStringProperty(properties, key, NULL);
wrapperData->outputFilters[i] = malloc(sizeof(char) * (strlen(val) + 1));
+ if (!wrapperData->outputFilters[i]) {
+ outOfMemory("LC", 3);
+ return TRUE;
+ }
strcpy(wrapperData->outputFilters[i], val);
/* Get the action */
@@ -3175,7 +3453,9 @@
#ifdef WIN32
/* Configure the NT service information */
- wrapperBuildNTServiceInfo();
+ if (wrapperBuildNTServiceInfo()) {
+ return TRUE;
+ }
if (wrapperData->requestThreadDumpOnFailedJVMExit) {
if (!wrapperData->ntAllocConsole) {
@@ -3189,12 +3469,14 @@
#else /* UNIX */
/* Configure the Unix daemon information */
- wrapperBuildUnixDaemonInfo();
+ if (wrapperBuildUnixDaemonInfo()) {
+ return TRUE;
+ }
#endif
wrapperData->configured = TRUE;
- return 0;
+ return FALSE;
}
/**
Modified: trunk/wrapper/src/c/wrapper.h
===================================================================
--- trunk/wrapper/src/c/wrapper.h 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapper.h 2007-04-02 07:30:44 UTC (rev 1316)
@@ -338,8 +338,11 @@
/**
* Returns the file name base as a newly malloced char *. The resulting
* base file name will have any path and extension stripped.
+ *
+ * baseName should be long enough to always contain the base name.
+ * (strlen(fileName) + 1) is safe.
*/
-extern char *wrapperGetFileBase(const char *fileName);
+extern void wrapperGetFileBase(const char *fileName, char *baseName);
/**
* Output the version.
Modified: trunk/wrapper/src/c/wrapper.ico
===================================================================
(Binary files differ)
Modified: trunk/wrapper/src/c/wrapperJNI_VC8.sln
===================================================================
--- trunk/wrapper/src/c/wrapperJNI_VC8.sln 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapperJNI_VC8.sln 2007-04-02 07:30:44 UTC (rev 1316)
@@ -1,24 +1,17 @@
-
-Microsoft Visual Studio Solution File, Format Version 9.00
+?\xBB\xBFMicrosoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "decoderJNI_VC8", "wrapperJNI_VC8.vcproj", "{0BE00FF2-0C30-463A-AF71-84242D234C0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
- Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
- Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0BE00FF2-0C30-463A-AF71-84242D234C0D}.Debug|Win32.ActiveCfg = Debug|Win32
{0BE00FF2-0C30-463A-AF71-84242D234C0D}.Debug|Win32.Build.0 = Debug|Win32
- {0BE00FF2-0C30-463A-AF71-84242D234C0D}.Debug|x64.ActiveCfg = Debug|x64
- {0BE00FF2-0C30-463A-AF71-84242D234C0D}.Debug|x64.Build.0 = Debug|x64
{0BE00FF2-0C30-463A-AF71-84242D234C0D}.Release|Win32.ActiveCfg = Release|Win32
{0BE00FF2-0C30-463A-AF71-84242D234C0D}.Release|Win32.Build.0 = Release|Win32
- {0BE00FF2-0C30-463A-AF71-84242D234C0D}.Release|x64.ActiveCfg = Release|x64
- {0BE00FF2-0C30-463A-AF71-84242D234C0D}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Modified: trunk/wrapper/src/c/wrapperJNI_VC8.vcproj
===================================================================
--- trunk/wrapper/src/c/wrapperJNI_VC8.vcproj 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapperJNI_VC8.vcproj 2007-04-02 07:30:44 UTC (rev 1316)
@@ -11,9 +11,6 @@
<Platform
Name="Win32"
/>
- <Platform
- Name="x64"
- />
</Platforms>
<ToolFiles>
</ToolFiles>
@@ -182,172 +179,6 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
- IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets=".\wrapper.vsprops"
- UseOfMFC="1"
- CharacterSet="0"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NON_CONFORMING_SWPRINTFS""
- Optimization="0"
- AdditionalIncludeDirectories="..\;"$(ProjectDir)";"$(javaHome)\include";"$(javaHome)\include\win32""
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DECODERJNI_VC8_EXPORTS"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- StructMemberAlignment="3"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="false"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="advapi32.lib user32.lib"
- OutputFile="$(InputDir)\..\..\lib\wrapper.dll"
- LinkIncremental="2"
- GenerateDebugInformation="true"
- SubSystem="2"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
- IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
- ConfigurationType="2"
- InheritedPropertySheets=".\wrapper.vsprops"
- UseOfMFC="1"
- CharacterSet="0"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NON_CONFORMING_SWPRINTFS""
- AdditionalIncludeDirectories="..\;"$(ProjectDir)";"$(javaHome)\include";"$(javaHome)\include\win32""
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DECODERJNI_VC8_EXPORTS"
- RuntimeLibrary="0"
- StructMemberAlignment="3"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="false"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="advapi32.lib user32.lib"
- OutputFile="$(InputDir)\..\..\lib\wrapper.dll"
- LinkIncremental="1"
- GenerateDebugInformation="true"
- SubSystem="2"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
</Configurations>
<References>
</References>
Modified: trunk/wrapper/src/c/wrapper_VC8.sln
===================================================================
--- trunk/wrapper/src/c/wrapper_VC8.sln 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapper_VC8.sln 2007-04-02 07:30:44 UTC (rev 1316)
@@ -5,19 +5,13 @@
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
- Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
- Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{18A1381E-03E3-486D-B34F-B73D21FBACB3}.Debug|Win32.ActiveCfg = Debug|Win32
{18A1381E-03E3-486D-B34F-B73D21FBACB3}.Debug|Win32.Build.0 = Debug|Win32
- {18A1381E-03E3-486D-B34F-B73D21FBACB3}.Debug|x64.ActiveCfg = Debug|x64
- {18A1381E-03E3-486D-B34F-B73D21FBACB3}.Debug|x64.Build.0 = Debug|x64
{18A1381E-03E3-486D-B34F-B73D21FBACB3}.Release|Win32.ActiveCfg = Release|Win32
{18A1381E-03E3-486D-B34F-B73D21FBACB3}.Release|Win32.Build.0 = Release|Win32
- {18A1381E-03E3-486D-B34F-B73D21FBACB3}.Release|x64.ActiveCfg = Release|x64
- {18A1381E-03E3-486D-B34F-B73D21FBACB3}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Modified: trunk/wrapper/src/c/wrapper_VC8.vcproj
===================================================================
--- trunk/wrapper/src/c/wrapper_VC8.vcproj 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapper_VC8.vcproj 2007-04-02 07:30:44 UTC (rev 1316)
@@ -1,442 +1,270 @@
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
- ProjectType="Visual C++"
- Version="8.00"
- Name="wrapper_VC8"
- ProjectGUID="{18A1381E-03E3-486D-B34F-B73D21FBACB3}"
- RootNamespace="wrapper_VC8"
- Keyword="Win32Proj"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- <Platform
- Name="x64"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="$(SolutionDir)$(IntDir)"
- IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)"
- ConfigurationType="1"
- UseOfMFC="1"
- CharacterSet="0"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- UseUnicodeResponseFiles="false"
- AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
- Optimization="0"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- StructMemberAlignment="3"
- BufferSecurityCheck="true"
- TreatWChar_tAsBuiltInType="true"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="wsock32.lib shlwapi.lib advapi32.lib user32.lib"
- OutputFile="$(InputDir)\..\..\bin\wrapper.exe"
- LinkIncremental="2"
- IgnoreDefaultLibraryNames=""
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeForWindows98="2"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|x64"
- OutputDirectory="$(SolutionDir)$(IntDir)"
- IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)"
- ConfigurationType="1"
- UseOfMFC="1"
- CharacterSet="0"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- UseUnicodeResponseFiles="false"
- AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
- Optimization="0"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- StructMemberAlignment="3"
- BufferSecurityCheck="true"
- TreatWChar_tAsBuiltInType="true"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="wsock32.lib shlwapi.lib advapi32.lib user32.lib"
- OutputFile="$(InputDir)\..\..\bin\wrapper.exe"
- LinkIncremental="2"
- IgnoreDefaultLibraryNames=""
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeForWindows98="2"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="$(SolutionDir)$(IntDir)"
- IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)"
- ConfigurationType="1"
- UseOfMFC="1"
- CharacterSet="0"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
- RuntimeLibrary="0"
- StructMemberAlignment="3"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="wsock32.lib shlwapi.lib advapi32.lib user32.lib"
- OutputFile="$(InputDir)\..\..\bin\wrapper.exe"
- LinkIncremental="1"
- IgnoreDefaultLibraryNames=""
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="2"
- TargetMachine="1"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Release|x64"
- OutputDirectory="$(SolutionDir)$(IntDir)"
- IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)"
- ConfigurationType="1"
- UseOfMFC="1"
- CharacterSet="0"
- WholeProgramOptimization="1"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- TargetEnvironment="3"
- />
- <Tool
- Name="VCCLCompilerTool"
- AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
- RuntimeLibrary="0"
- StructMemberAlignment="3"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLinkerTool"
- AdditionalOptions="wsock32.lib shlwapi.lib advapi32.lib user32.lib"
- OutputFile="$(InputDir)\..\..\bin\wrapper.exe"
- LinkIncremental="1"
- IgnoreDefaultLibraryNames=""
- GenerateDebugInformation="true"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- OptimizeForWindows98="2"
- TargetMachine="17"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCManifestTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCAppVerifierTool"
- />
- <Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
- >
- <File
- RelativePath=".\logger.c"
- >
- </File>
- <File
- RelativePath=".\property.c"
- >
- </File>
- <File
- RelativePath=".\wrapper.c"
- >
- </File>
- <File
- RelativePath=".\wrapper_unix.c"
- >
- </File>
- <File
- RelativePath=".\wrapper_win.c"
- >
- </File>
- <File
- RelativePath=".\wrappereventloop.c"
- >
- </File>
- <File
- RelativePath=".\wrapperinfo.c"
- >
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc;xsd"
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
- >
- <File
- RelativePath=".\logger.h"
- >
- </File>
- <File
- RelativePath=".\messages.h"
- >
- </File>
- <File
- RelativePath=".\property.h"
- >
- </File>
- <File
- RelativePath=".\resource.h"
- >
- </File>
- <File
- RelativePath=".\wrapper.h"
- >
- </File>
- <File
- RelativePath=".\wrapperinfo.h"
- >
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
- >
- <File
- RelativePath=".\messages.mc"
- >
- </File>
- <File
- RelativePath=".\Wrapper.rc"
- >
- </File>
- </Filter>
- </Files>
- <Globals>
- </Globals>
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="wrapper_VC8"
+ ProjectGUID="{18A1381E-03E3-486D-B34F-B73D21FBACB3}"
+ RootNamespace="wrapper_VC8"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(IntDir)"
+ IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)"
+ ConfigurationType="1"
+ UseOfMFC="1"
+ CharacterSet="0"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ UseUnicodeResponseFiles="false"
+ AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ StructMemberAlignment="3"
+ BufferSecurityCheck="true"
+ TreatWChar_tAsBuiltInType="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions="wsock32.lib shlwapi.lib advapi32.lib user32.lib"
+ OutputFile="$(InputDir)\..\..\bin\wrapper.exe"
+ LinkIncremental="2"
+ IgnoreDefaultLibraryNames=""
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeForWindows98="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(IntDir)"
+ IntermediateDirectory="$(ProjectName)__$(PlatformName)_$(ConfigurationName)"
+ ConfigurationType="1"
+ UseOfMFC="1"
+ CharacterSet="0"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="0"
+ StructMemberAlignment="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalOptions="wsock32.lib shlwapi.lib advapi32.lib user32.lib"
+ OutputFile="$(InputDir)\..\..\bin\wrapper.exe"
+ LinkIncremental="1"
+ IgnoreDefaultLibraryNames=""
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ OptimizeForWindows98="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\logger.c"
+ >
+ </File>
+ <File
+ RelativePath=".\property.c"
+ >
+ </File>
+ <File
+ RelativePath=".\wrapper.c"
+ >
+ </File>
+ <File
+ RelativePath=".\wrapper_unix.c"
+ >
+ </File>
+ <File
+ RelativePath=".\wrapper_win.c"
+ >
+ </File>
+ <File
+ RelativePath=".\wrappereventloop.c"
+ >
+ </File>
+ <File
+ RelativePath=".\wrapperinfo.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\logger.h"
+ >
+ </File>
+ <File
+ RelativePath=".\messages.h"
+ >
+ </File>
+ <File
+ RelativePath=".\property.h"
+ >
+ </File>
+ <File
+ RelativePath=".\resource.h"
+ >
+ </File>
+ <File
+ RelativePath=".\wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\wrapperinfo.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath=".\messages.mc"
+ >
+ </File>
+ <File
+ RelativePath=".\Wrapper.rc"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
</VisualStudioProject>
Modified: trunk/wrapper/src/c/wrapper_unix.c
===================================================================
--- trunk/wrapper/src/c/wrapper_unix.c 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapper_unix.c 2007-04-02 07:30:44 UTC (rev 1316)
@@ -708,11 +708,19 @@
}
/* Allocate memory to hold array of command strings */
- wrapperData->jvmCommand = malloc(sizeof(char *) * (length + 1));
+ wrapperData->jvmCommand = malloc(sizeof(char *) * (length + 1));
+ if (!wrapperData->jvmCommand) {
+ outOfMemory("WBJC", 1);
+ return TRUE;
+ }
/* number of arguments + 1 for a NULL pointer at the end */
for (i = 0; i <= length; i++) {
if (i < length) {
wrapperData->jvmCommand[i] = malloc(sizeof(char) * (strlen(strings[i]) + 1));
+ if (!wrapperData->jvmCommand[i]) {
+ outOfMemory("WBJC", 2);
+ return TRUE;
+ }
strcpy(wrapperData->jvmCommand[i], strings[i]);
} else {
wrapperData->jvmCommand[i] = NULL;
@@ -990,12 +998,19 @@
int childOutputBufferSize = 0;
/**
* Make sure there is enough space in the outputBuffer.
+ *
+ * return TRUE if there were any problems.
*/
-void ensureSpaceInChildOutputBuffer(int childOutputBufferPos, int requiredSpace) {
+int ensureSpaceInChildOutputBuffer(int childOutputBufferPos, int requiredSpace) {
char *tempBuf;
if ( childOutputBufferPos >= childOutputBufferSize - requiredSpace ) {
tempBuf = malloc(sizeof(char) * (childOutputBufferSize + 1024));
+ if (!tempBuf) {
+ outOfMemory("ESICOB", 1);
+ return TRUE;
+ }
+
if (childOutputBuffer != NULL) {
/* Copy over the old data */
memcpy(tempBuf, childOutputBuffer, childOutputBufferSize);
@@ -1006,6 +1021,8 @@
childOutputBuffer = tempBuf;
childOutputBufferSize += 1024;
}
+
+ return FALSE;
}
/**
@@ -1091,7 +1108,9 @@
if (childOutputBufferPos > 0) {
/* We have a partial line, write it out so it is not lost. */
- ensureSpaceInChildOutputBuffer( childOutputBufferPos, 1 );
+ if (ensureSpaceInChildOutputBuffer( childOutputBufferPos, 1 )) {
+ return 0;
+ }
childOutputBuffer[childOutputBufferPos] = '\0';
wrapperLogChildOutput(childOutputBuffer);
childOutputBufferPos = 0;
@@ -1107,7 +1126,9 @@
for (readBufPos = 0; readBufPos < bytesRead; readBufPos++) {
if (readBuf[readBufPos] == (char)0x0a) {
/* Line feed; write out buffer and reset it. */
- ensureSpaceInChildOutputBuffer( childOutputBufferPos, 1 );
+ if (ensureSpaceInChildOutputBuffer( childOutputBufferPos, 1 )) {
+ return 0;
+ }
childOutputBuffer[childOutputBufferPos] = '\0';
wrapperLogChildOutput(childOutputBuffer);
childOutputBufferPos = 0;
@@ -1117,7 +1138,9 @@
return -1;
}
} else {
- ensureSpaceInChildOutputBuffer( childOutputBufferPos, 2 );
+ if (ensureSpaceInChildOutputBuffer( childOutputBufferPos, 2 )) {
+ return 0;
+ }
/* Add character to write buffer. */
childOutputBuffer[childOutputBufferPos++] = readBuf[readBufPos];
@@ -1386,6 +1409,8 @@
return 1; /* For compiler. */
}
+ wrapperVersionBanner();
+
/* Change the working directory if configured to do so. */
if (wrapperData->workingDir && wrapperSetWorkingDir(wrapperData->workingDir)) {
appExit(1);
Modified: trunk/wrapper/src/c/wrapper_win.c
===================================================================
--- trunk/wrapper/src/c/wrapper_win.c 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapper_win.c 2007-04-02 07:30:44 UTC (rev 1316)
@@ -156,7 +156,7 @@
/**
* Builds an array in memory of the system path.
*/
-void buildSystemPath() {
+int buildSystemPath() {
char *envBuffer;
size_t len, i;
char *c, *lc;
@@ -164,13 +164,17 @@
/* Get the length of the PATH environment variable. */
len = GetEnvironmentVariable("PATH", NULL, 0);
if (len == 0) {
- /* PATH not set on this system */
+ /* PATH not set on this system. Not an error. */
systemPath[0] = NULL;
- return;
+ return 0;
}
/* Allocate the memory to hold the PATH */
envBuffer = malloc(sizeof(char) * len);
+ if (!envBuffer) {
+ outOfMemory("BSP", 1);
+ return 1;
+ }
GetEnvironmentVariable("PATH", envBuffer, (DWORD)len);
#ifdef _DEBUG
@@ -187,6 +191,11 @@
{
len = (int)(c - lc);
systemPath[i] = malloc(sizeof(char) * (len + 1));
+ if (!systemPath[i]) {
+ outOfMemory("BSP", 2);
+ return 1;
+ }
+
memcpy(systemPath[i], lc, len);
systemPath[i][len] = '\0';
#ifdef _DEBUG
@@ -198,6 +207,10 @@
/* There should be one more value after the last ';' */
len = strlen(lc);
systemPath[i] = malloc(sizeof(char) * (len + 1));
+ if (!systemPath[i]) {
+ outOfMemory("BSP", 3);
+ return 1;
+ }
strcpy(systemPath[i], lc);
#ifdef _DEBUG
printf("PATH[%d]=%s\n", i, systemPath[i]);
@@ -212,6 +225,8 @@
/* Release the environment variable memory. */
free(envBuffer);
+
+ return 0;
}
char** wrapperGetSystemPath() {
return systemPath;
@@ -226,6 +241,10 @@
char *mutexName;
if (wrapperData->isSingleInvocation) {
mutexName = malloc(sizeof(char) * (23 + strlen(wrapperData->ntServiceName) + 1));
+ if (!mutexName) {
+ outOfMemory("IIM", 1);
+ return 1;
+ }
sprintf(mutexName, "Java Service Wrapper - %s", wrapperData->ntServiceName);
if (!(invocationMutexHandle = CreateMutex(NULL, FALSE, mutexName))) {
@@ -634,6 +653,10 @@
/* Build the actual command */
wrapperData->jvmCommand = malloc(sizeof(char) * commandLen);
+ if (!wrapperData->jvmCommand) {
+ outOfMemory("WBJC", 1);
+ return TRUE;
+ }
commandLen = 0;
for (i = 0; i < length; i++) {
if (i > 0) {
@@ -1036,7 +1059,7 @@
* This is so that we can always add a \0 to the end of it. */
wrapperChildStdoutRdBuffer = malloc(sizeof(CHAR) * (READ_BUFFER_BLOCK_SIZE + 1));
if (!wrapperChildStdoutRdBuffer) {
- log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, "Out of memory allocating child read buffer.");
+ outOfMemory("WRCO", 1);
return 0;
}
wrapperChildStdoutRdBufferSize = READ_BUFFER_BLOCK_SIZE + 1;
@@ -1077,6 +1100,10 @@
wrapperChildStdoutRdBufferSize, wrapperChildStdoutRdBufferSize + READ_BUFFER_BLOCK_SIZE);
*/
newBuffer = malloc(sizeof(char) * (wrapperChildStdoutRdBufferSize + READ_BUFFER_BLOCK_SIZE));
+ if (!newBuffer) {
+ outOfMemory("WRCO", 2);
+ return 0;
+ }
strcpy(newBuffer, wrapperChildStdoutRdBuffer);
bufferP = newBuffer + (bufferP - wrapperChildStdoutRdBuffer);
free(wrapperChildStdoutRdBuffer);
@@ -1995,6 +2022,11 @@
int cnt = 0;
buffer = malloc(sizeof(char) * 65);
+ if (!buffer) {
+ outOfMemory("RP", 1);
+ appExit(0);
+ return NULL;
+ }
buffer[0] = 0;
do {
@@ -2277,7 +2309,9 @@
#endif
/* Found an environment variable in the registry. Set it to the current environment. */
envKeys[dwIndex] = malloc(MAX_PROPERTY_NAME_LENGTH - 1 + MAX_PROPERTY_VALUE_LENGTH - 1 + 2);
- if (envKeys[dwIndex] != NULL) {
+ if (!envKeys[dwIndex]) {
+ outOfMemory("WLEFRI", 1);
+ } else {
sprintf(envKeys[dwIndex], "%s=%s", name, data);
if (_putenv(envKeys[dwIndex])) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, "Unable to set environment variable from the registry - %s", getLastErrorText());
@@ -2491,6 +2525,11 @@
return 0;
}
value = malloc(valueSize);
+ if (!value) {
+ outOfMemory("WGJFWR", 1);
+ RegCloseKey(openHKey);
+ return 0;
+ }
if (RegQueryValueEx(openHKey, valueKey, NULL, &valueType, value, &valueSize) != ERROR_SUCCESS) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_ERROR,
"Unable to access configured registry location %s - (%d)", prop, errno);
@@ -2551,6 +2590,11 @@
return 0;
}
value = malloc(valueSize);
+ if (!value) {
+ outOfMemory("WGJFWR", 2);
+ RegCloseKey(openHKey);
+ return 0;
+ }
if (RegQueryValueEx(openHKey, "JavaHome", NULL, &valueType, value, &valueSize) != ERROR_SUCCESS) {
RegCloseKey(openHKey);
return 0;
@@ -3078,6 +3122,11 @@
/* Get the service configuration. */
QueryServiceConfig(schService, NULL, 0, &reqSize);
pQueryServiceConfig = malloc(reqSize);
+ if (!pQueryServiceConfig) {
+ outOfMemory("WSS", 1);
+ CloseServiceHandle(schSCManager);
+ return 0;
+ }
if (QueryServiceConfig(schService, pQueryServiceConfig, reqSize, &reqSize)) {
switch (pQueryServiceConfig->dwStartType) {
case SERVICE_BOOT_START: /* Possible? */
@@ -3239,14 +3288,30 @@
* Sets the working directory to that of the current executable
*/
int setWorkingDir() {
- char szPath[512];
+ int size = 128;
+ char* szPath = NULL;
+ int result;
char* pos;
-
- /* Get the full path and filename of this program */
- if (GetModuleFileName(NULL, szPath, 512) == 0){
- log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, "Unable to get the path-%s", getLastErrorText());
- return 1;
- }
+
+ /* How large a buffer is needed? The GetModuleFileName function doesn't tell us how much
+ * is needed, only if it is too short. */
+ do {
+ szPath = malloc(sizeof(TCHAR) * size);
+ if (!szPath) {
+ outOfMemory("SWD", 1);
+ return 1;
+ }
+ result = GetModuleFileName(NULL, szPath, size);
+ if (result <= 0) {
+ log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, "Unable to get the path-%s", getLastErrorText());
+ return 1;
+ } else if (result >= size) {
+ /* Too small. */
+ size += 128;
+ free(szPath);
+ szPath = NULL;
+ }
+ } while (!szPath);
/* The wrapperData->isDebugging flag will never be set here, so we can't really use it. */
#ifdef _DEBUG
@@ -3257,13 +3322,17 @@
pos = strrchr(szPath, '\\');
if (pos == NULL) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, "Unable to extract path from: %s", szPath);
+ free(szPath);
return 1;
} else {
/* Clip the path at the position of the last backslash */
pos[0] = (char)0;
}
- return wrapperSetWorkingDir(szPath);
+ result = wrapperSetWorkingDir(szPath);
+ free(szPath);
+
+ return result;
}
/******************************************************************************
@@ -3353,7 +3422,9 @@
exName = getExceptionName(exCode);
if (exName == NULL) {
exName = malloc(sizeof(char) * 64); /* Let this leak. It only happens once before shutdown. */
- sprintf(exName, "Unknown Exception (%ld)", exCode);
+ if (exName) {
+ sprintf(exName, "Unknown Exception (%ld)", exCode);
+ }
}
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, " exceptionCode = %s", exName);
@@ -3363,10 +3434,10 @@
if (exCode == EXCEPTION_ACCESS_VIOLATION) {
if (exceptionPointers->ExceptionRecord->ExceptionInformation[0] == 0) {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, " Read access exception from %p",
- (int)exceptionPointers->ExceptionRecord->ExceptionInformation[1]);
+ exceptionPointers->ExceptionRecord->ExceptionInformation[1]);
} else {
log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_FATAL, " Write access exception to %p",
- (int)exceptionPointers->ExceptionRecord->ExceptionInformation[1]);
+ exceptionPointers->ExceptionRecord->ExceptionInformation[1]);
}
} else {
for (i = 0; i < (int)exceptionPointers->ExceptionRecord->NumberParameters; i++) {
@@ -3391,7 +3462,10 @@
* the table; */
SERVICE_TABLE_ENTRY serviceTable[2];
- buildSystemPath();
+ if (buildSystemPath()) {
+ appExit(1);
+ return; /* For clarity. */
+ }
if (wrapperInitialize()) {
appExit(1);
Modified: trunk/wrapper/src/c/wrapperjni_unix.c
===================================================================
--- trunk/wrapper/src/c/wrapperjni_unix.c 2007-03-23 16:32:24 UTC (rev 1315)
+++ trunk/wrapper/src/c/wrapperjni_unix.c 2007-04-02 07:30:44 UTC (rev 1316)
@@ -90,7 +90,10 @@
}
int wrapperReleaseControlEventQueue() {
- pthread_mutex_unlock(&controlEventQueueMutex);
+ if (pthread_mutex_unlock(&controlEventQueueMutex)) {
+ printf("WrapperJNI Error: Failed to unlock the event queue mutex.\n");
+ fflush(NULL);
+ }
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|