Skip to content

Commit 048ee0a

Browse files
Fix JDWP ThreadReference.frames
* Fix case where the length is unspecified but the start frame is > 0 * Return error packets on invalid parameters
1 parent dc50bc4 commit 048ee0a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/ErrorCodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class ErrorCodes {
5050
public static final int ABSENT_INFORMATION = 101;
5151
public static final int INVALID_EVENT_TYPE = 102;
5252
public static final int INTERNAL = 113;
53+
public static final int INVALID_INDEX = 503;
5354
public static final int INVALID_LENGTH = 504;
5455
public static final int INVALID_STRING = 506;
5556
public static final int INVALID_CLASS_LOADER = 507;

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/impl/JDWP.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,8 +2111,7 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
21112111
}
21122112

21132113
int startFrame = input.readInt();
2114-
int length = input.readInt();
2115-
final int requestedLength = length;
2114+
int requestedLength = input.readInt();
21162115

21172116
controller.fine(() -> "requesting frames for thread: " + controller.getContext().getThreadName(thread));
21182117
controller.fine(() -> "startFrame requested: " + startFrame);
@@ -2127,13 +2126,21 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
21272126
}
21282127

21292128
CallFrame[] frames = suspendedInfo.getStackFrames();
2130-
2131-
if (length == -1 || length > frames.length) {
2132-
length = frames.length;
2129+
if (startFrame < 0 || startFrame >= frames.length) {
2130+
reply.errorCode(ErrorCodes.INVALID_INDEX);
2131+
return new CommandResult(reply);
2132+
}
2133+
int length;
2134+
if (requestedLength == -1) {
2135+
length = frames.length - startFrame;
2136+
} else if (requestedLength < 0 || startFrame + requestedLength > frames.length) {
2137+
reply.errorCode(ErrorCodes.INVALID_LENGTH);
2138+
return new CommandResult(reply);
2139+
} else {
2140+
length = requestedLength;
21332141
}
21342142
reply.writeInt(length);
2135-
final int finalLength = length;
2136-
controller.fine(() -> "returning " + finalLength + " frames for thread: " + controller.getContext().getThreadName(thread));
2143+
controller.fine(() -> "returning " + length + " frames for thread: " + controller.getContext().getThreadName(thread));
21372144

21382145
for (int i = startFrame; i < startFrame + length; i++) {
21392146
CallFrame frame = frames[i];

0 commit comments

Comments
 (0)