-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reject illegal entries in the bootstrap argument array #2700
Reject illegal entries in the bootstrap argument array #2700
Conversation
Code Reviewer: @DanHeidinga |
runtime/bcutil/cfreader.c
Outdated
* CONSTANT_Double_info, CONSTANT_MethodHandle_info, or CONSTANT_MethodType_info structure. | ||
*/ | ||
cpValueTag = cpBase[value].tag; | ||
if ((CFR_CONSTANT_String != cpValueTag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be clearer as a switch statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already updated against suggestion.
runtime/bcutil/cfreader.c
Outdated
&& (CFR_CONSTANT_Float != cpValueTag) | ||
&& (CFR_CONSTANT_Double != cpValueTag) | ||
&& (CFR_CONSTANT_MethodHandle != cpValueTag) | ||
&& (CFR_CONSTANT_MethodType != cpValueTag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, for JDK11, what about Constant_Dynamic? It should be allowed as a BSM arg as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already double-checked the Spec at http://openjdk.java.net/jeps/309 and added Constant_Dynamic as valid structure.
runtime/nls/cfre/cfrerr.nls
Outdated
@@ -1362,3 +1362,11 @@ J9NLS_CFR_ERR_CP_ENTRY_INVALID_BEFORE_V55.explanation=Please consult the Java Vi | |||
J9NLS_CFR_ERR_CP_ENTRY_INVALID_BEFORE_V55.system_action=The JVM will throw a verification or classloading-related exception such as java.lang.ClassFormatError. | |||
J9NLS_CFR_ERR_CP_ENTRY_INVALID_BEFORE_V55.user_response=Contact the provider of the classfile for a corrected version. | |||
# END NON-TRANSLATABLE | |||
|
|||
J9NLS_CFR_ERR_BAD_BOOTSTRAP_ARGUMENT_ENTRY=The bootstrap argument array contains illegal indices to the constant pool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the message be updated to something like:
BootstrapMethod (%d) arguments contain invalid constantpool entry at index (%d) of type (%d)
So that it contains the BSM index, the cp entry and the cp entries type? It makes it much easier for users to understand what went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally introduced 2 parameters (bsmMethodIndex and bsmArgumentIndex) for this message but didn't move forward because the modification of the existing method buildError() incurs a bunch of unnecessary updating at all places.
From the user perspective, I am customizing a new method buildBootstrapMethodError() (still in coding) which only addresses this issue. Will see whether it works good in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a crash with my new changes. Still investigating to see what happens to my code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already fixed the bug in the new changes.
898c8e4
to
8e5c77e
Compare
Already finished the new changes and it works good as expected:
|
8e5c77e
to
1bd2033
Compare
runtime/verutil/cfrerr.c
Outdated
/* J9NLS_CFR_ERR_BAD_BOOTSTRAP_ARGUMENT_ENTRY=BootstrapMethod (%1$d) arguments contain invalid constantpool entry at index (#%2$u) of type (%3$u); class=%5$.*4$s, offset=%6$u */ | ||
template = j9nls_lookup_message(J9NLS_ERROR | J9NLS_DO_NOT_APPEND_NEWLINE, J9NLS_CFR_ERR_BAD_BOOTSTRAP_ARGUMENT_ENTRY, "(%d)(#%u)(%u);%.*s,%u"); | ||
|
||
allocSize = strlen(template) + classNameLength + MAX_INT_SIZE * 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add brackets to the MAX_INT_SIZE * 4
so it's immediately obvious that you intended to multiple the max int size by 4, and not the entire amount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already fixed as suggested.
runtime/verutil/cfrerr.c
Outdated
PORT_ACCESS_FROM_PORT(portLib); | ||
UDATA allocSize = 0; | ||
char *errorString = NULL; | ||
const char *template; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either assign j9nls_lookup_message()
's return value to this variable directly or initialize it to null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already fixed as suggested.
1bd2033
to
7572bf4
Compare
Jenkins test sanity xlinux jdk8,jdk11 |
@ChengJin01 the build is failing - can you take a look?
|
Will investigate to see what happened in there. |
The changes are to validate the entries stored in the bootstrap argument array to ensure they are valid constant pool index required in the JVM Spec. Signed-off-by: CHENGJin <[email protected]>
7572bf4
to
33096e2
Compare
Jenkins test sanity xlinux jdk8,jdk11 |
1 similar comment
Jenkins test sanity xlinux jdk8,jdk11 |
I'm OK with merging this now but would like to see some tests added for this. In particular, to validate that the error cases print reasonable messages and don't crash :) Opened #2856 for adding tests. |
The changes are to validate the entries stored in
the bootstrap argument array to ensure they are
valid constant pool index required in the JVM Spec.
Signed-off-by: CHENGJin [email protected]