Skip to content

Commit

Permalink
Fix the crash issue with the error message framework in Verifier
Browse files Browse the repository at this point in the history
The change is to resolve the crash issue specific to a stackmap
frame without any element in 'locals' and 'stack' when allocating
the memory of stackmap frame in the error message framework during
the runtime verification.

Fixes: eclipse-openj9#15639

Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
  • Loading branch information
ChengJin01 committed Aug 8, 2022
1 parent 41430ff commit 0e45a9f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion runtime/verbose/errormessagehelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,27 @@ decodeConstuctedStackMapFrameData(StackMapFrame* stackMapFrame, U_8* nextStackma
VerificationTypeInfo* currentVerificationTypeEntry = stackMapFrame->entries;
U_16 maxStack = methodInfo->maxStack;
U_16 maxLocals = methodInfo->maxLocals;
IDATA lastIndex = stackBaseIndex - 1;
/* The layout of 'locals' and 'stack' in each stackmap frame of a constructed stackmaps looks as follows:
* +-----------------------+------------------+
* | locals | stack |
* +-----------------------+------------------+
* 0 | |
* lastIndex stackBaseIndex
* It shows that stackBaseIndex points to the 1st element of 'stack' while lastIndex points to
* the last element of 'locals'.
*
* Initially, both stackBaseIndex and stackTopIndex are set to -1 by default before the stackmaps
* are constructed internally against the class bytecode (class version <= 50) via simulateStack(),
* in which case both 'locals' and 'stack' are empty in each stackmap frame of the stackmaps.
* (See the code of initializing stackmaps in j9bcv_verifyBytecodes() at bcverify.c)
*
* Thus, there are 3 cases in terms of a given stackmap frame of the constructed stackmaps:
* 1)if stackBaseIndex == -1(which means that both 'locals' and 'stack' are empty), lastIndex is -1.
* 2)if stackBaseIndex == 0 (which means that there is 1 element in 'locals'), lastIndex is 0.
* 3)if stackBaseIndex >= 1 (which means that there is at least 1 element in 'locals'),
* lastIndex is (stackBaseIndex - 1).
*/
IDATA lastIndex = (stackBaseIndex >= 1) ? (stackBaseIndex - 1) : stackBaseIndex;
IDATA slot = 0;
IDATA dataTypeCode = DATATYPE_1_SLOT;
BOOLEAN nonTopFound = FALSE;
Expand Down Expand Up @@ -807,6 +827,7 @@ releaseVerificationTypeBuffer(StackMapFrame* stackMapFrame, MethodContextInfo* m
if (NULL != stackMapFrame->entries) {
PORT_ACCESS_FROM_PORT(methodInfo->portLib);
j9mem_free_memory(stackMapFrame->entries);
stackMapFrame->entries = NULL;
}
}

Expand Down

0 comments on commit 0e45a9f

Please sign in to comment.