Skip to content

Commit 42e0308

Browse files
authored
[TS] Add checks to forbid fake objects (#335)
1 parent 407b68a commit 42e0308

File tree

6 files changed

+15
-3
lines changed

6 files changed

+15
-3
lines changed

usvm-ts/src/main/kotlin/org/usvm/machine/expr/CallApproximations.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ private fun TsExprResolver.handleArrayPop(
344344
"Array.pop() should have no arguments, but got ${expr.args.size}"
345345
}
346346

347+
checkNotFake(array)
348+
347349
scope.calcOnState {
348350
// Read the length of the array
349351
val lengthLValue = mkArrayLengthLValue(array, arrayType)

usvm-ts/src/main/kotlin/org/usvm/machine/expr/ExprUtil.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import org.usvm.machine.types.ExprWithTypeConstraint
2020
import org.usvm.types.single
2121
import org.usvm.util.boolToFp
2222

23+
fun TsContext.checkNotFake(expr: UExpr<*>) {
24+
require(!expr.isFakeObject()) {
25+
"Fake object handling should be done outside of this function"
26+
}
27+
}
28+
2329
fun TsContext.mkTruthyExpr(
2430
expr: UExpr<out USort>,
2531
scope: TsStepScope,

usvm-ts/src/main/kotlin/org/usvm/machine/expr/ReadArray.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ fun TsContext.readArray(
6868
index: UExpr<TsSizeSort>,
6969
arrayType: EtsArrayType,
7070
): UExpr<*>? {
71+
checkNotFake(array)
72+
7173
// Read the array length.
7274
val length = scope.calcOnState {
7375
val lengthLValue = mkArrayLengthLValue(array, arrayType)

usvm-ts/src/main/kotlin/org/usvm/machine/expr/ReadField.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ fun TsContext.readField(
6363
field: EtsFieldSignature,
6464
hierarchy: EtsHierarchy,
6565
): UExpr<*> {
66-
require(!instance.isFakeObject()) {
67-
"Fake object handling should be done outside of this function"
68-
}
66+
checkNotFake(instance)
6967

7068
val sort = when (val etsField = resolveEtsField(instanceLocal, field, hierarchy)) {
7169
is TsResolutionResult.Empty -> {

usvm-ts/src/main/kotlin/org/usvm/machine/expr/ReadLength.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fun TsContext.readArrayLength(
4242
array: UHeapRef,
4343
arrayType: EtsArrayType,
4444
): UExpr<KFp64Sort> {
45+
checkNotFake(array)
46+
4547
// Read the length of the array.
4648
val length = scope.calcOnState {
4749
val lengthLValue = mkArrayLengthLValue(array, arrayType)

usvm-ts/src/main/kotlin/org/usvm/machine/expr/WriteArray.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ fun TsContext.assignToArrayIndex(
6666
expr: UExpr<*>,
6767
arrayType: EtsArrayType,
6868
): Unit? {
69+
checkNotFake(array)
70+
6971
// Read the array length.
7072
val length = scope.calcOnState {
7173
val lengthLValue = mkArrayLengthLValue(array, arrayType)

0 commit comments

Comments
 (0)