Skip to content

Commit

Permalink
Update the error message for invalid class name
Browse files Browse the repository at this point in the history
The change is to add code so as to improve the readability
of the error message being thrown out when an invalid class
name stored in the constant pool is captured during the bytecode
verification.

Related: #7684

Signed-off-by: Cheng Jin <[email protected]>
  • Loading branch information
Cheng Jin committed Feb 7, 2020
1 parent 9de47a9 commit 51f5c7b
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 107 deletions.
14 changes: 7 additions & 7 deletions runtime/bcutil/verifyerrstring.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2019 IBM Corp. and others
* Copyright (c) 1991, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -38,7 +38,7 @@ buildVerifyErrorString( J9JavaVM *javaVM, J9CfrError *error, U_8* className, UDA
if(error->errorMethod == -1) {
errorString = getJ9CfrErrorDetailMessageNoMethod(
PORTLIB,
error,
error,
className,
classNameLength);
} else {
Expand Down Expand Up @@ -69,11 +69,11 @@ buildVerifyErrorString( J9JavaVM *javaVM, J9CfrError *error, U_8* className, UDA

/* Jazz 82615: Append the error message framework to the existing error string */
errorString = getJ9CfrErrorDetailMessageForMethod(
PORTLIB,
error,
className,
classNameLength,
name->bytes,
PORTLIB,
error,
className,
classNameLength,
name->bytes,
name->slot1,
sig->bytes,
sig->slot1,
Expand Down
4 changes: 3 additions & 1 deletion runtime/bcverify/j9bcverify.tdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//*******************************************************************************
// Copyright (c) 2006, 2019 IBM Corp. and others
// Copyright (c) 2006, 2020 IBM Corp. and others
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -212,3 +212,5 @@ TraceExit=Trc_RTV_findClassRelationship_Exit Overhead=1 Level=3 Template="findCl
TraceEntry=Trc_RTV_freeClassRelationshipParentNodes_Entry Overhead=1 Level=3 Template="freeClassRelationshipParentNodes - class: %.*s"
TraceEvent=Trc_RTV_freeClassRelationshipParentNodes_Parent Overhead=1 Level=3 Template="freeClassRelationshipParentNodes - parent: %.*s"
TraceExit=Trc_RTV_freeClassRelationshipParentNodes_Exit Overhead=1 Level=3 Template="freeClassRelationshipParentNodes - returning"

TraceException=Trc_STV_j9bcv_verifyClassStructure_BadClassNameError NoEnv Overhead=1 Level=1 Template="j9bcv_verifyClassStructure: BadClassNameError - formatError %x, errorNo = %d, cpIndex = %d, className = %.*s"
43 changes: 32 additions & 11 deletions runtime/bcverify/staticverify.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2019 IBM Corp. and others
* Copyright (c) 1991, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -38,6 +38,11 @@
#define FALLBACK_CLASS_FORMAT_ERROR -2
#define FALLBACK_VERIFY_ERROR -3

#define CLASS_NAME_ERR_UTF8 1
#define CLASS_NAME_ERR_OBJECT_ARRAY 2
#define CLASS_NAME_ERR_BASE_TYPE_ARRAY 3
#define CLASS_NAME_ERR_DEFAULT 4

typedef struct StackmapExceptionDetails {
I_32 stackmapFrameIndex;
U_32 stackmapFrameBCI;
Expand Down Expand Up @@ -1635,9 +1640,12 @@ j9bcv_verifyClassStructure (J9PortLibrary * portLib, J9CfrClassFile * classfile,
J9CfrConstantPoolInfo *info;
J9CfrConstantPoolInfo *utf8;
J9CfrMethod *method;
const U_32 thisClassIndex = classfile->constantPool[classfile->thisClass].slot1;
J9CfrConstantPoolInfo classNameInfo = {0, 0, 0, 0, 0, NULL, 0};
U_32 classNameErrNo = 0;
U_32 cpIndex = 0;

Trc_STV_j9bcv_verifyClassStructure_Entry(classfile->constantPool[classfile->constantPool[classfile->thisClass].slot1].slot1,
classfile->constantPool[classfile->constantPool[classfile->thisClass].slot1].bytes);
Trc_STV_j9bcv_verifyClassStructure_Entry(classfile->constantPool[thisClassIndex].slot1, classfile->constantPool[thisClassIndex].bytes);

for (i = 1; i < classfile->constantPoolCount; i++) {
J9CfrConstantPoolInfo *nameAndSig;
Expand All @@ -1650,10 +1658,14 @@ j9bcv_verifyClassStructure (J9PortLibrary * portLib, J9CfrClassFile * classfile,
case CFR_CONSTANT_Class:
/* Must be a UTF8. */
utf8 = &classfile->constantPool[info->slot1];
classNameInfo.slot1 = utf8->slot1;
classNameInfo.bytes = utf8->bytes;
cpIndex = i;
arity = bcvCheckClassName(utf8);
if (arity < 0) {
errorType = J9NLS_CFR_ERR_BAD_CLASS_NAME__ID;
goto _formatError;
errorType = J9NLS_CFR_ERR_CP_BAD_CLASS_NAME__ID;
classNameErrNo = CLASS_NAME_ERR_UTF8;
goto _classNameError;
}

if (arity > 0) { /* we have some sort of array */
Expand All @@ -1666,8 +1678,9 @@ j9bcv_verifyClassStructure (J9PortLibrary * portLib, J9CfrClassFile * classfile,
switch (utf8->bytes[arity]) {
case 'L': /* object array */
if (utf8->bytes[--end] != ';') {
errorType = J9NLS_CFR_ERR_BAD_CLASS_NAME__ID;
goto _formatError;
errorType = J9NLS_CFR_ERR_CP_BAD_CLASS_NAME__ID;
classNameErrNo = CLASS_NAME_ERR_OBJECT_ARRAY;
goto _classNameError;
}
break;
case 'B': /* base type array */
Expand All @@ -1679,13 +1692,15 @@ j9bcv_verifyClassStructure (J9PortLibrary * portLib, J9CfrClassFile * classfile,
case 'S':
case 'Z':
if (--end != (UDATA) arity) {
errorType = J9NLS_CFR_ERR_BAD_CLASS_NAME__ID;
goto _formatError;
errorType = J9NLS_CFR_ERR_CP_BAD_CLASS_NAME__ID;
classNameErrNo = CLASS_NAME_ERR_BASE_TYPE_ARRAY;
goto _classNameError;
}
break;
default:
errorType = J9NLS_CFR_ERR_BAD_CLASS_NAME__ID;
goto _formatError;
errorType = J9NLS_CFR_ERR_CP_BAD_CLASS_NAME__ID;
classNameErrNo = CLASS_NAME_ERR_DEFAULT;
goto _classNameError;
}
}

Expand Down Expand Up @@ -1894,6 +1909,12 @@ j9bcv_verifyClassStructure (J9PortLibrary * portLib, J9CfrClassFile * classfile,

goto _leaveProc; /* All is well */

_classNameError:
Trc_STV_j9bcv_verifyClassStructure_BadClassNameError(J9NLS_CFR_ERR_CP_BAD_CLASS_NAME__ID, classNameErrNo, cpIndex, classNameInfo.slot1, classNameInfo.bytes);
buildClassNameError((J9CfrError *)segment, errorType, CFR_ThrowClassFormatError, info->romAddress, classNameErrNo, cpIndex, thisClassIndex, classfile->constantPool);
result = -1;
goto _leaveProc;

_formatError:
Trc_STV_j9bcv_verifyClassStructure_ClassError(errorType, info->romAddress);
buildError((J9CfrError *)segment, errorType, CFR_ThrowClassFormatError, info->romAddress);
Expand Down
Loading

0 comments on commit 51f5c7b

Please sign in to comment.