commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1197541 - in /commons/proper/daemon/trunk/src/native/windows: apps/prunsrv/prunsrv.c src/javajni.c
Date Fri, 04 Nov 2011 12:52:09 GMT
Author: mturk
Date: Fri Nov  4 12:52:08 2011
New Revision: 1197541

URL: http://svn.apache.org/viewvc?rev=1197541&view=rev
Log:
Make a code a bit safer on invalid parameters. Make sure it doesn't crash at least

Modified:
    commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/windows/src/javajni.c

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c?rev=1197541&r1=1197540&r2=1197541&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c Fri Nov  4 12:52:08
2011
@@ -1303,9 +1303,15 @@ void WINAPI serviceMain(DWORD argc, LPTS
     if (IS_VALID_STRING(SO_STARTMODE)) {
         if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
             _jni_startup = TRUE;
-            _jni_rclass  = WideToANSI(SO_STARTCLASS);
-            /* Exchange all dots with slashes */
-            apxStrCharReplaceA(_jni_rclass, '.', '/');
+            if (IS_VALID_STRING(SO_STARTCLASS)) {
+                _jni_rclass  = WideToANSI(SO_STARTCLASS);
+                /* Exchange all dots with slashes */
+                apxStrCharReplaceA(_jni_rclass, '.', '/');
+            }
+            else {
+                /* Presume its main */
+                _jni_rclass = WideToANSI(L"Main");
+            }
             _jni_rparam = SO_STARTPARAMS;
         }
         else if (!lstrcmpiW(SO_STARTMODE, PRSRV_JAVA)) {
@@ -1345,14 +1351,14 @@ void WINAPI serviceMain(DWORD argc, LPTS
     if (IS_VALID_STRING(SO_STOPMODE)) {
         if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
             _jni_shutdown = TRUE;
-            _jni_sclass = WideToANSI(SO_STOPCLASS);
             if (IS_VALID_STRING(SO_STOPCLASS)) {
+                _jni_sclass = WideToANSI(SO_STOPCLASS);
                 apxStrCharReplaceA(_jni_sclass, '.', '/');
-                _jni_sparam = SO_STOPPARAMS;
             }
             else {
-                _jni_sclass = "java/lang/System";
+                _jni_sclass = WideToANSI(L"java/lang/System");
             }
+            _jni_sparam = SO_STOPPARAMS;
         }
         else if (!lstrcmpiW(SO_STOPMODE, PRSRV_JAVA)) {
             LPWSTR jx = NULL, szJH = SO_JAVAHOME;

Modified: commons/proper/daemon/trunk/src/native/windows/src/javajni.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/javajni.c?rev=1197541&r1=1197540&r2=1197541&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/javajni.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/javajni.c Fri Nov  4 12:52:08 2011
@@ -792,8 +792,18 @@ apxJavaLoadMainClass(APXHANDLE hJava, LP
     if (hJava->dwType != APXHANDLE_TYPE_JVM)
         return FALSE;
     lpJava = APXHANDLE_DATA(hJava);
-    if (!__apxJvmAttach(lpJava))
+    if (!lpJava)
         return FALSE;
+    if (IS_EMPTY_STRING(szMethodName))
+        szMethodName = "main";
+    if (lstrcmpA(szClassName, "java/lang/System") == 0) {
+        /* Usable only for exit method, so force */
+        szSignature  = "(I)V";
+        szMethodName = "exit";
+    }
+    lstrlcpyA(lpJava->clWorker.sClazz, 1024, szClassName);
+    lstrlcpyA(lpJava->clWorker.sMethod, 512, szMethodName);
+
     jClazz = JNICALL_1(FindClass, JAVA_CLASSSTRING);
     if (!jClazz) {
         JVM_EXCEPTION_CLEAR(lpJava);
@@ -802,7 +812,6 @@ apxJavaLoadMainClass(APXHANDLE hJava, LP
     }
     lpJava->clString.jClazz = JNICALL_1(NewGlobalRef, jClazz);
     JNI_LOCAL_UNREF(jClazz);
-
     /* Find the class */
     jClazz  = JNICALL_1(FindClass, szClassName);
     if (!jClazz) {
@@ -814,15 +823,6 @@ apxJavaLoadMainClass(APXHANDLE hJava, LP
     lpJava->clWorker.jClazz  = JNICALL_1(NewGlobalRef, jClazz);
     JNI_LOCAL_UNREF(jClazz);
 
-    if (!szMethodName)
-        szMethodName = "main";
-    if (lstrcmpA(szClassName, "java/lang/System") == 0) {
-        /* Usable only for exit method, so force */
-        szSignature  = "(I)V";
-        szMethodName = "exit";
-    }
-    lstrlcpyA(lpJava->clWorker.sClazz, 1024, szClassName);
-    lstrlcpyA(lpJava->clWorker.sMethod, 512, szMethodName);
     lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
                                          lpJava->clWorker.jClazz,
                                          szMethodName, szSignature);
@@ -855,16 +855,18 @@ apxJavaLoadMainClass(APXHANDLE hJava, LP
  */
 static DWORD WINAPI __apxJavaWorkerThread(LPVOID lpParameter)
 {
-#define WORKER_EXIT(x)  { rv = x; goto finished; }
+#define WORKER_EXIT(x)  do { rv = x; goto finished; } while(0)
     DWORD rv = 0;
-    LPAPXJAVAVM lpJava;
+    LPAPXJAVAVM lpJava = NULL;
     LPAPXJAVA_THREADARGS pArgs = (LPAPXJAVA_THREADARGS)lpParameter;
     APXHANDLE hJava;
 
-    hJava = (APXHANDLE)pArgs->hJava;
+    hJava  = (APXHANDLE)pArgs->hJava;
     if (hJava->dwType != APXHANDLE_TYPE_JVM)
         WORKER_EXIT(1);
-
+    lpJava = APXHANDLE_DATA(pArgs->hJava);
+    if (!lpJava)
+        WORKER_EXIT(1);
     if (!apxJavaInitialize(pArgs->hJava,
                            pArgs->szClassPath,
                            pArgs->lpOptions,
@@ -882,17 +884,16 @@ static DWORD WINAPI __apxJavaWorkerThrea
                               pArgs->szClassName,
                               pArgs->szMethodName,
                               pArgs->lpArguments)) {
-        WORKER_EXIT(2);
+        WORKER_EXIT(3);
     }
     apxJavaSetOut(pArgs->hJava, TRUE,  pArgs->szStdErrFilename);
     apxJavaSetOut(pArgs->hJava, FALSE, pArgs->szStdOutFilename);
 
-    lpJava = APXHANDLE_DATA(pArgs->hJava);
     /* Check if we have a class and a method */
     if (!lpJava->clWorker.jClazz || !lpJava->clWorker.jMethod)
-        WORKER_EXIT(2);
+        WORKER_EXIT(4);
     if (!__apxJvmAttach(lpJava))
-        WORKER_EXIT(3);
+        WORKER_EXIT(5);
     apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread started %s:%s",
                 lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
     lpJava->dwWorkerStatus = 1;
@@ -902,26 +903,30 @@ static DWORD WINAPI __apxJavaWorkerThrea
               lpJava->clWorker.jMethod,
               lpJava->clWorker.jArgs);
     if (JVM_EXCEPTION_CHECK(lpJava)) {
-        WORKER_EXIT(4);
+        WORKER_EXIT(6);
     }
     else {
         __apxJvmDetach(lpJava);
     }
 finished:
-    lpJava->dwWorkerStatus = 0;
-    apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished %s:%s with status=%d",
-                lpJava->clWorker.sClazz, lpJava->clWorker.sMethod, rv);
-    SetEvent(lpJava->hWorkerSync);
+    if (lpJava) {
+        lpJava->dwWorkerStatus = 0;
+        apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished %s:%s with status=%d",
+                    lpJava->clWorker.sClazz, lpJava->clWorker.sMethod, rv);
+        SetEvent(lpJava->hWorkerSync);
+    }
     ExitThread(rv);
     /* never gets here but keep the compiler happy */
-    return 0;
+    return rv;
 }
 
+BOOL
 apxJavaStart(LPAPXJAVA_THREADARGS pArgs)
 {
-
     LPAPXJAVAVM lpJava;
     lpJava = APXHANDLE_DATA(pArgs->hJava);
+    if (!lpJava)
+        return FALSE;
     lpJava->dwWorkerStatus = 0;
     lpJava->hWorkerSync    = CreateEvent(NULL, FALSE, FALSE, NULL);
     lpJava->hWorkerThread  = CreateThread(NULL,
@@ -936,6 +941,8 @@ apxJavaStart(LPAPXJAVA_THREADARGS pArgs)
     ResumeThread(lpJava->hWorkerThread);
     /* Wait until the worker thread initializes */
     WaitForSingleObject(lpJava->hWorkerSync, INFINITE);
+    if (lpJava->dwWorkerStatus == 0)
+        return FALSE;
     if (lstrcmpA(lpJava->clWorker.sClazz, "java/lang/System")) {
         /* Give some time to initialize the thread
          * Unless we are calling System.exit(0).



Mime
View raw message