8186163: [JVMCI] bad signatures should be detected by MetaAccessProvider.parseMethodDescriptor
Reviewed-by: kvn, iveresov
This commit is contained in:
parent
2157043054
commit
750f00f851
@ -45,7 +45,9 @@ public class HotSpotSignature implements Signature {
|
|||||||
|
|
||||||
public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, String signature) {
|
public HotSpotSignature(HotSpotJVMCIRuntimeProvider runtime, String signature) {
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
assert signature.length() > 0;
|
if (signature.length() == 0) {
|
||||||
|
throw new IllegalArgumentException("Signature cannot be empty");
|
||||||
|
}
|
||||||
this.originalString = signature;
|
this.originalString = signature;
|
||||||
|
|
||||||
if (signature.charAt(0) == '(') {
|
if (signature.charAt(0) == '(') {
|
||||||
@ -59,9 +61,11 @@ public class HotSpotSignature implements Signature {
|
|||||||
cur++;
|
cur++;
|
||||||
int nextCur = parseSignature(signature, cur);
|
int nextCur = parseSignature(signature, cur);
|
||||||
returnType = signature.substring(cur, nextCur);
|
returnType = signature.substring(cur, nextCur);
|
||||||
assert nextCur == signature.length();
|
if (nextCur != signature.length()) {
|
||||||
|
throw new IllegalArgumentException("Extra characters at end of signature: " + signature);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
returnType = null;
|
throw new IllegalArgumentException("Signature must start with a '(': " + signature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,15 +85,20 @@ public class HotSpotSignature implements Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int parseSignature(String signature, int start) {
|
private static int parseSignature(String signature, int start) {
|
||||||
|
try {
|
||||||
int cur = start;
|
int cur = start;
|
||||||
char first;
|
char first;
|
||||||
do {
|
do {
|
||||||
first = signature.charAt(cur++);
|
first = signature.charAt(cur);
|
||||||
|
cur++;
|
||||||
} while (first == '[');
|
} while (first == '[');
|
||||||
|
|
||||||
switch (first) {
|
switch (first) {
|
||||||
case 'L':
|
case 'L':
|
||||||
while (signature.charAt(cur) != ';') {
|
while (signature.charAt(cur) != ';') {
|
||||||
|
if (signature.charAt(cur) == '.') {
|
||||||
|
throw new IllegalArgumentException("Class name in signature contains '.' at index " + cur + ": " + signature);
|
||||||
|
}
|
||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
cur++;
|
cur++;
|
||||||
@ -105,9 +114,12 @@ public class HotSpotSignature implements Signature {
|
|||||||
case 'Z':
|
case 'Z':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new JVMCIError("Invalid character at index %d in signature: %s", cur, signature);
|
throw new IllegalArgumentException("Invalid character '" + signature.charAt(cur - 1) + "' at index " + (cur - 1) + " in signature: " + signature);
|
||||||
}
|
}
|
||||||
return cur;
|
return cur;
|
||||||
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
|
throw new IllegalArgumentException("Truncated signature: " + signature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,8 +83,9 @@ public interface MetaAccessProvider {
|
|||||||
/**
|
/**
|
||||||
* Parses a
|
* Parses a
|
||||||
* <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.3">method
|
* <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.3">method
|
||||||
* descriptor</a> into a {@link Signature}. The behavior of this method is undefined if the
|
* descriptor</a> into a {@link Signature}.
|
||||||
* method descriptor is not well formed.
|
*
|
||||||
|
* @throws IllegalArgumentException if the method descriptor is not well formed
|
||||||
*/
|
*/
|
||||||
Signature parseMethodDescriptor(String methodDescriptor);
|
Signature parseMethodDescriptor(String methodDescriptor);
|
||||||
|
|
||||||
|
@ -257,4 +257,15 @@ public class TestMetaAccessProvider extends TypeUniverse {
|
|||||||
assertEquals("Unexpected debugId", metaAccess.decodeDebugId(value), DEBUG_IDS[i]);
|
assertEquals("Unexpected debugId", metaAccess.decodeDebugId(value), DEBUG_IDS[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseSignatureTest() {
|
||||||
|
for (String badSig : new String[]{"", "()", "(", "()Vextra", "()E", "(E)", "(Ljava.lang.Object;)V"}) {
|
||||||
|
try {
|
||||||
|
metaAccess.parseMethodDescriptor(badSig);
|
||||||
|
throw new AssertionError("Expected signature to be invalid: " + badSig);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user