Skip to content

Commit 69e3a8b

Browse files
Merge pull request #59 from lisa-analyzer/fix/mk-method-in-taint-analysis
Add head and tail parameters to constructors and mk methods
2 parents 9f1fa89 + a40e0d7 commit 69e3a8b

File tree

3 files changed

+59
-35
lines changed

3 files changed

+59
-35
lines changed

src/main/java/it/unipr/analysis/taint/RandomnessDependencyAbstractDomain.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,32 @@
66
import java.util.Set;
77

88
public class RandomnessDependencyAbstractDomain extends TaintAbstractDomain {
9+
910
private static final RandomnessDependencyAbstractDomain TOP = new RandomnessDependencyAbstractDomain(
10-
createFilledArray(TaintAbstractDomain.STACK_LIMIT, TaintElement.BOTTOM), TaintElement.CLEAN);
11-
private static final RandomnessDependencyAbstractDomain BOTTOM = new RandomnessDependencyAbstractDomain(null,
11+
createFilledArray(TaintAbstractDomain.STACK_LIMIT, TaintElement.BOTTOM), 0, 0, TaintElement.CLEAN);
12+
private static final RandomnessDependencyAbstractDomain BOTTOM = new RandomnessDependencyAbstractDomain(null, 0, 0,
1213
TaintElement.BOTTOM);
1314

1415
/**
15-
* Builds an initial symbolic stack.
16+
* Constructs a new {@code RandomnessDependencyAbstractDomain} with an empty
17+
* (BOTTOM) stack, zero head/tail, and CLEAN memory state.
1618
*/
1719
public RandomnessDependencyAbstractDomain() {
18-
this(createFilledArray(STACK_LIMIT, TaintElement.BOTTOM), TaintElement.CLEAN);
20+
this(createFilledArray(STACK_LIMIT, TaintElement.BOTTOM), 0, 0, TaintElement.CLEAN);
1921
}
2022

2123
/**
22-
* Builds a taint abstract stack starting from a given stack and a list of
23-
* elements that push taint.
24+
* Constructs a new {@code RandomnessDependencyAbstractDomain} with the
25+
* given stack state, stack pointers, and memory state.
2426
*
25-
* @param stack the stack of values
27+
* @param stack the stack array containing taint information for each
28+
* element
29+
* @param head the current head pointer of the stack
30+
* @param tail the current tail pointer of the stack
31+
* @param memory the taint state of the memory
2632
*/
27-
protected RandomnessDependencyAbstractDomain(TaintElement[] stack, TaintElement memory) {
28-
super(stack, memory);
33+
protected RandomnessDependencyAbstractDomain(TaintElement[] stack, int head, int tail, TaintElement memory) {
34+
super(stack, head, tail, memory);
2935
}
3036

3137
@Override
@@ -52,8 +58,7 @@ public RandomnessDependencyAbstractDomain bottom() {
5258
}
5359

5460
@Override
55-
public TaintAbstractDomain mk(TaintElement[] stack, TaintElement memory) {
56-
return new RandomnessDependencyAbstractDomain(stack, memory);
61+
public TaintAbstractDomain mk(TaintElement[] stack, int head, int tail, TaintElement memory) {
62+
return new RandomnessDependencyAbstractDomain(stack, head, tail, memory);
5763
}
58-
5964
}

src/main/java/it/unipr/analysis/taint/TaintAbstractDomain.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,30 @@ public abstract class TaintAbstractDomain
7474
private final TaintElement memory;
7575

7676
/**
77-
* Builds a taint abstract stack starting from a given stack and a list of
78-
* elements that push taint. Builds a taint abstract stack starting from a
79-
* given stack and a memory element.
77+
* Builds a taint abstract stack starting from a given stack and a taint
78+
* memory. Builds a taint abstract stack starting from a given stack and a
79+
* memory element.
8080
*
8181
* @param stack the stack of values
8282
* @param memory the memory element
8383
*/
8484
protected TaintAbstractDomain(TaintElement[] stack, TaintElement memory) {
85+
this(stack, 0, 0, memory);
86+
}
87+
88+
/**
89+
* Builds a taint abstract stack starting from a given stack, its head
90+
* index, its tail index and a taint memory. Builds a taint abstract stack
91+
* starting from a given stack and a memory element.
92+
*
93+
* @param stack the stack of values
94+
* @param memory the memory element
95+
*/
96+
protected TaintAbstractDomain(TaintElement[] stack, int head, int tail, TaintElement memory) {
8597
this.stack = stack;
8698
this.memory = memory;
87-
this.head = 0;
88-
this.tail = 0;
99+
this.head = head;
100+
this.tail = tail;
89101
}
90102

91103
@Override
@@ -187,7 +199,7 @@ public TaintAbstractDomain smallStepSemantics(ValueExpression expression, Progra
187199
resultStack.popX(3);
188200

189201
if (this.isTainted((Statement) pp))
190-
return mk(resultStack.stack, TaintElement.TAINT);
202+
return mk(resultStack.stack, resultStack.head, resultStack.tail, TaintElement.TAINT);
191203

192204
return resultStack;
193205
}
@@ -233,7 +245,7 @@ else if (memory.isClean())
233245
TaintElement value = resultStack.pop();
234246

235247
if (value.isTaint())
236-
return mk(resultStack.stack, TaintElement.TAINT);
248+
return mk(resultStack.stack, resultStack.head, resultStack.tail, TaintElement.TAINT);
237249
else if (value.isClean())
238250
return resultStack;
239251
}
@@ -749,7 +761,7 @@ public TaintAbstractDomain glbAux(TaintAbstractDomain other) throws SemanticExce
749761
for (int i = 0; i < STACK_LIMIT; i++) {
750762
result[i] = this.get(i).glb(other.get(i));
751763
}
752-
return mk(result, this.memory.glb(other.memory));
764+
return mk(result, this.head, this.tail, this.memory.glb(other.memory));
753765
}
754766

755767
/**
@@ -767,7 +779,7 @@ public TaintAbstractDomain lubAux(TaintAbstractDomain other) throws SemanticExce
767779
for (int i = 0; i < STACK_LIMIT; i++) {
768780
result[i] = this.get(i).lub(other.get(i));
769781
}
770-
return mk(result, this.memory.lub(other.memory));
782+
return mk(result, this.head, this.tail, this.memory.lub(other.memory));
771783
}
772784

773785
/**
@@ -859,7 +871,7 @@ public boolean hasBottomUntil(int x) {
859871
@Override
860872
public TaintAbstractDomain clone() {
861873
TaintElement[] newArray = stack.clone();
862-
TaintAbstractDomain copy = mk(newArray, memory);
874+
TaintAbstractDomain copy = mk(newArray, head, tail, memory);
863875
copy.head = this.head;
864876
copy.tail = this.tail;
865877
return copy;
@@ -955,12 +967,14 @@ else if (isTop())
955967

956968
/**
957969
* Utility for creating a concrete instance of {@link TaintAbstractDomain}
958-
* given the stack and the memory.
970+
* given the stack, its head index, its tail index and the memory.
959971
*
960972
* @param stack the stack
973+
* @param head the head index
974+
* @param tail the tail index
961975
* @param memory the memory
962976
*
963977
* @return a new concrete instance of {@link TaintAbstractDomain}
964978
*/
965-
public abstract TaintAbstractDomain mk(TaintElement[] stack, TaintElement memory);
979+
public abstract TaintAbstractDomain mk(TaintElement[] stack, int head, int tail, TaintElement memory);
966980
}

src/main/java/it/unipr/analysis/taint/TxOriginAbstractDomain.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,29 @@
88
public class TxOriginAbstractDomain extends TaintAbstractDomain {
99

1010
private static final TxOriginAbstractDomain TOP = new TxOriginAbstractDomain(
11-
createFilledArray(TaintAbstractDomain.STACK_LIMIT, TaintElement.BOTTOM), TaintElement.CLEAN);
12-
private static final TxOriginAbstractDomain BOTTOM = new TxOriginAbstractDomain(null, TaintElement.BOTTOM);
11+
createFilledArray(TaintAbstractDomain.STACK_LIMIT, TaintElement.BOTTOM), 0, 0, TaintElement.CLEAN);
12+
private static final TxOriginAbstractDomain BOTTOM = new TxOriginAbstractDomain(null, 0, 0, TaintElement.BOTTOM);
1313

1414
/**
15-
* Builds an initial symbolic stack.
15+
* Constructs a new {@code TxOriginAbstractDomain} with an empty (BOTTOM)
16+
* stack, zero head/tail, and CLEAN memory state.
1617
*/
1718
public TxOriginAbstractDomain() {
18-
this(createFilledArray(STACK_LIMIT, TaintElement.BOTTOM), TaintElement.CLEAN);
19+
this(createFilledArray(STACK_LIMIT, TaintElement.BOTTOM), 0, 0, TaintElement.CLEAN);
1920
}
2021

2122
/**
22-
* Builds a taint abstract stack starting from a given stack and a list of
23-
* elements that push taint.
23+
* Constructs a new {@code TxOriginAbstractDomain} with the given stack
24+
* state, stack pointers, and memory state.
2425
*
25-
* @param stack the stack of values
26+
* @param stack the stack array containing taint information for each
27+
* element
28+
* @param head the current head pointer of the stack
29+
* @param tail the current tail pointer of the stack
30+
* @param memory the taint state of the memory
2631
*/
27-
protected TxOriginAbstractDomain(TaintElement[] stack, TaintElement memory) {
28-
super(stack, memory);
32+
protected TxOriginAbstractDomain(TaintElement[] stack, int head, int tail, TaintElement memory) {
33+
super(stack, head, tail, memory);
2934
}
3035

3136
@Override
@@ -49,7 +54,7 @@ public TxOriginAbstractDomain bottom() {
4954
}
5055

5156
@Override
52-
public TaintAbstractDomain mk(TaintElement[] stack, TaintElement memory) {
53-
return new TxOriginAbstractDomain(stack, memory);
57+
public TaintAbstractDomain mk(TaintElement[] stack, int head, int tail, TaintElement memory) {
58+
return new TxOriginAbstractDomain(stack, head, tail, memory);
5459
}
5560
}

0 commit comments

Comments
 (0)