mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 06:14:49 +02:00
8349624: Validation for slot missing in CodeBuilder local variable instructions
Reviewed-by: asotona
This commit is contained in:
parent
a1bcda2476
commit
32dc41c9f7
2 changed files with 60 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
|
@ -484,7 +484,7 @@ public final class DirectCodeBuilder
|
|||
bytecodesBufWriter.writeU1(opcode.bytecode());
|
||||
}
|
||||
|
||||
// Instruction version, refer to opcode
|
||||
// Instruction version, refer to opcode, trusted
|
||||
public void writeLocalVar(Opcode opcode, int slot) {
|
||||
if (opcode.isWide()) {
|
||||
bytecodesBufWriter.writeU2U2(opcode.bytecode(), slot);
|
||||
|
@ -493,12 +493,12 @@ public final class DirectCodeBuilder
|
|||
}
|
||||
}
|
||||
|
||||
// Shortcut version, refer to and validate slot
|
||||
private void writeLocalVar(int bytecode, int slot) {
|
||||
// TODO validation like (slot & 0xFFFF) == slot
|
||||
if (slot < 256) {
|
||||
// local var access, not a trusted write method, needs slot validation
|
||||
private void localAccess(int bytecode, int slot) {
|
||||
if ((slot & ~0xFF) == 0) {
|
||||
bytecodesBufWriter.writeU1U1(bytecode, slot);
|
||||
} else {
|
||||
BytecodeHelpers.validateSlot(slot);
|
||||
bytecodesBufWriter.writeU1U1U2(WIDE, bytecode, slot);
|
||||
}
|
||||
}
|
||||
|
@ -989,7 +989,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(ALOAD_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(ALOAD, slot);
|
||||
localAccess(ALOAD, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1017,7 +1017,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(ASTORE_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(ASTORE, slot);
|
||||
localAccess(ASTORE, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1100,7 +1100,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(DLOAD_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(DLOAD, slot);
|
||||
localAccess(DLOAD, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1134,7 +1134,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(DSTORE_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(DSTORE, slot);
|
||||
localAccess(DSTORE, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1246,7 +1246,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(FLOAD_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(FLOAD, slot);
|
||||
localAccess(FLOAD, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1280,7 +1280,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(FSTORE_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(FSTORE, slot);
|
||||
localAccess(FSTORE, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1506,7 +1506,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(ILOAD_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(ILOAD, slot);
|
||||
localAccess(ILOAD, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1606,7 +1606,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(ISTORE_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(ISTORE, slot);
|
||||
localAccess(ISTORE, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1701,7 +1701,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(LLOAD_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(LLOAD, slot);
|
||||
localAccess(LLOAD, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -1753,7 +1753,7 @@ public final class DirectCodeBuilder
|
|||
if (slot >= 0 && slot <= 3) {
|
||||
bytecodesBufWriter.writeU1(LSTORE_0 + slot);
|
||||
} else {
|
||||
writeLocalVar(LSTORE, slot);
|
||||
localAccess(LSTORE, slot);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue