harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r814555 - in /harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent: commands/ClassType.cpp commands/EventRequest.cpp commands/ObjectReference.cpp core/ExceptionManager.h core/PacketParser.cpp
Date Mon, 14 Sep 2009 10:11:23 GMT
Author: hindessm
Date: Mon Sep 14 10:11:22 2009
New Revision: 814555

URL: http://svn.apache.org/viewvc?rev=814555&view=rev
Log:
Fix some error cases where we are not throwing required exceptions.

Modified:
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/EventRequest.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h
    harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp?rev=814555&r1=814554&r2=814555&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ClassType.cpp
Mon Sep 14 10:11:22 2009
@@ -33,8 +33,10 @@
 int 
 ClassType::SuperClassHandler::Execute(JNIEnv *jni)
 {
-    //INVALID_OBJECT can be thrown below
+    //INVALID_CLASS or INVALID_OBJECT can be thrown below
     jclass clazz = m_cmdParser->command.ReadReferenceTypeID(jni);
+    JDWP_CHECK_NOT_NULL(clazz);
+
     JDWP_TRACE(LOG_RELEASE, (LOG_DATA_FL, "SuperClass: received: classID=%p", clazz));
 
     // get superclass
@@ -66,6 +68,8 @@
 {
     //INVALID_CLASS or INVALID_OBJECT can be thrown below
     jclass clazz = m_cmdParser->command.ReadReferenceTypeID(jni);
+    JDWP_CHECK_NOT_NULL(clazz);
+
     jint values = m_cmdParser->command.ReadInt();
     JDWP_TRACE(LOG_RELEASE, (LOG_DATA_FL, "SetValues: received: classID=%p, values=%d", clazz,
values));
 
@@ -226,7 +230,10 @@
 ClassType::InvokeMethodHandler::Execute(JNIEnv *jni)
 {
     m_clazz = m_cmdParser->command.ReadReferenceTypeID(jni);
+    JDWP_CHECK_NOT_NULL(m_clazz);
     m_thread = m_cmdParser->command.ReadThreadID(jni);
+    JDWP_CHECK_NOT_NULL(m_thread);
+
     m_methodID = m_cmdParser->command.ReadMethodID(jni);
     jint arguments = m_cmdParser->command.ReadInt();
 
@@ -261,7 +268,7 @@
         return JDWP_ERROR_INVALID_METHODID;
     }
 
-    // check that given method is stsic method
+    // check that given method is static method
     jint methodModifiers;
     JVMTI_TRACE(LOG_DEBUG, err, jvmti->GetMethodModifiers(m_methodID, &methodModifiers));
     if (err != JVMTI_ERROR_NONE) {

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/EventRequest.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/EventRequest.cpp?rev=814555&r1=814554&r2=814555&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/EventRequest.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/EventRequest.cpp
Mon Sep 14 10:11:22 2009
@@ -35,6 +35,7 @@
     jdwpSuspendPolicy suspendPolicy =
         (jdwpSuspendPolicy) m_cmdParser->command.ReadByte();
     jint modCount = m_cmdParser->command.ReadInt();
+    jdwpError jdwpErr;
 
     JDWP_TRACE(LOG_RELEASE, (LOG_DATA_FL, "Set: event=%s, eventKind=%d, suspendPolicy=%d,
modCount=%d",
                     GetRequestManager().GetEventKindName(eventKind), eventKind, suspendPolicy,
modCount));
@@ -195,6 +196,13 @@
                 }
                 m_cmdParser->command.ReadByte(); // typeTag
                 jclass cls = m_cmdParser->command.ReadReferenceTypeID(jni);
+                if (cls == 0) {
+                    AgentException e(JDWP_ERROR_INVALID_CLASS);
+                    JDWP_SET_EXCEPTION(e);
+                    delete request;
+                    return JDWP_ERROR_INVALID_CLASS;
+                }
+
                 jmethodID method = m_cmdParser->command.ReadMethodID(jni);
                 jlocation loc = m_cmdParser->command.ReadLong();
 
@@ -223,6 +231,12 @@
                     return JDWP_ERROR_ILLEGAL_ARGUMENT;
                 }
                 jclass cls = m_cmdParser->command.ReadReferenceTypeIDOrNull(jni);
+                jdwpErr = JDWP_LAST_ERROR_CODE;
+                if (jdwpErr != JDWP_ERROR_NONE) {
+                    delete request;
+                    return jdwpErr;
+                }
+
                 jboolean caught = m_cmdParser->command.ReadBoolean();
                 jboolean uncaught = m_cmdParser->command.ReadBoolean();
 
@@ -252,7 +266,7 @@
                     return JDWP_ERROR_ILLEGAL_ARGUMENT;
                 }
                 jclass cls = m_cmdParser->command.ReadReferenceTypeID(jni);
-                                    if (cls == 0) {
+                if (cls == 0) {
                     AgentException e(JDWP_ERROR_INVALID_CLASS);
                     JDWP_SET_EXCEPTION(e);
                     delete request;

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp?rev=814555&r1=814554&r2=814555&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/commands/ObjectReference.cpp
Mon Sep 14 10:11:22 2009
@@ -302,6 +302,7 @@
     jobject jvmObject = m_cmdParser->command.ReadObjectID(jni);
     // Can be: InternalErrorException, OutOfMemoryException,
     // JDWP_ERROR_INVALID_OBJECT
+    JDWP_CHECK_ERROR_CODE(jdwpErr);
    
     jclass jvmClass = jni->GetObjectClass(jvmObject); 
     jint fieldsNumber = m_cmdParser->command.ReadInt();

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h?rev=814555&r1=814554&r2=814555&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/ExceptionManager.h
Mon Sep 14 10:11:22 2009
@@ -48,6 +48,10 @@
                                     return value; \
                                  }
 
+#define JDWP_CHECK_NOT_NULL(value) if (value != NULL) {\
+                                    return JDWP_LAST_ERROR_CODE; \
+                                 }
+
 namespace jdwp {
 
     typedef hythread_t ThreadId_t;

Modified: harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp?rev=814555&r1=814554&r2=814555&view=diff
==============================================================================
--- harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp
(original)
+++ harmony/enhanced/jdktools/branches/java6/modules/jpda/src/main/native/jdwp/common/agent/core/PacketParser.cpp
Mon Sep 14 10:11:22 2009
@@ -290,6 +290,14 @@
 
 jobject InputPacketParser::ReadObjectID(JNIEnv *jni) {
     jobject obj = ReadObjectIDOrNull(jni);
+
+    // if the ID was invalid we already have an exception so we just
+    // need to check the case when it is null
+    if (!obj && !JDWP_HAS_EXCEPTION) {
+      JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "ReadObjectID returned null"));
+      AgentException ex(JDWP_ERROR_INVALID_OBJECT);
+      JDWP_SET_EXCEPTION(ex);
+    }
     return obj;
 }
 
@@ -307,34 +315,47 @@
         // For a ObjectID, we should convert it to ReferenceTypeID 
         // if it is a ClassObjectID
         jobject obj = GetObjectManager().MapFromObjectID(jni, rtid);
-        jclass clsType = jni->GetObjectClass(obj);
-        jboolean isClass = jni->IsAssignableFrom(clsType, jni->GetObjectClass(clsType));

-        if (!isClass){
-            JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "## ReadReferenceTypeIDOrNul: read : ObjectID
is not a ClassObjectID"));
-            return 0;
-        }
-        
-        cls = static_cast<jclass> (obj);
-        jboolean isValidID = GetObjectManager().FindObjectID(jni, cls, rtid); 
-        if(!isValidID){
-            JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "## ReadReferenceTypeIDOrNul: read : ID
is an invalid ObjectID"));
-            return 0;
+        if (obj) {
+          jclass clsType = jni->GetObjectClass(obj);
+          jboolean isClass = jni->IsAssignableFrom(clsType, jni->GetObjectClass(clsType));

+          if (isClass) {
+            JDWP_TRACE(LOG_RELEASE, (LOG_DATA_FL, "## ReadReferenceTypeIDOrNul: read : ObjectID
is a ClassObjectID"));
+            cls = static_cast<jclass> (obj);
+            jboolean isValidID = GetObjectManager().FindObjectID(jni, cls, rtid); 
+            if(!isValidID) {
+              JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "## ReadReferenceTypeIDOrNul: read :
ID is an invalid ObjectID"));
+              AgentException ex(JDWP_ERROR_INVALID_OBJECT);
+              JDWP_SET_EXCEPTION(ex);
+              return 0;
+            }
+          }
         }
-    }else { 
+    }
+
+    if (cls == 0) {
         // convert to jclass (actually to WeakReference or GlobalReference)
         cls = GetObjectManager().MapFromReferenceTypeID(jni, rtid);
     }
 
-    JDWP_ASSERT(cls != 0);
+    if (!cls) {
+        JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "## ReadReferenceTypeIDOrNul: read : ID is
invalid"));
+        AgentException ex(JDWP_ERROR_INVALID_OBJECT);
+        JDWP_SET_EXCEPTION(ex);
+        return 0;
+    }
     
     // make GlobalReference and check if WeakReference was freed
     jclass ref = static_cast<jclass>(jni->NewGlobalRef(cls));
     if (ref == 0) {
         if (jni->IsSameObject(cls, 0)) {
             JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "Invalid object calling NewGlobalRef"));
+            AgentException ex(JDWP_ERROR_INVALID_OBJECT);
+            JDWP_SET_EXCEPTION(ex);
             return 0;
         } else {
             JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "Out of memory calling NewGlobalRef"));
+            AgentException ex(JDWP_ERROR_OUT_OF_MEMORY);
+            JDWP_SET_EXCEPTION(ex);
             return 0;
         }
     }
@@ -346,6 +367,15 @@
 
 jclass InputPacketParser::ReadReferenceTypeID(JNIEnv *jni) {
     jclass cls = ReadReferenceTypeIDOrNull(jni);
+
+    // if the ID was invalid we already have an exception so we just
+    // need to check the case when it is null
+    if (!cls && !JDWP_HAS_EXCEPTION) {
+      JDWP_TRACE(LOG_RELEASE,
+                 (LOG_ERROR_FL, "ReadReferenceTypeID returned null"));
+      AgentException ex(JDWP_ERROR_INVALID_OBJECT);
+      JDWP_SET_EXCEPTION(ex);
+    }
     return cls;
 }
 
@@ -426,6 +456,14 @@
     
 jthread InputPacketParser::ReadThreadID(JNIEnv *jni) {
     jthread thrd = ReadThreadIDOrNull(jni);
+
+    // if the ID was invalid we already have an exception so we just
+    // need to check the case when it is null
+    if (!thrd && !JDWP_HAS_EXCEPTION) {
+      JDWP_TRACE(LOG_RELEASE, (LOG_ERROR_FL, "ReadThreadID returned null"));
+      AgentException ex(JDWP_ERROR_INVALID_OBJECT);
+      JDWP_SET_EXCEPTION(ex);
+    }
     return thrd;
 }
 



Mime
View raw message