Skip to content

Commit c202839

Browse files
committed
Bug fixing for HF privacy analysis
1 parent cb43576 commit c202839

File tree

3 files changed

+73
-49
lines changed

3 files changed

+73
-49
lines changed

go-lisa/src/main/java/it/unive/golisa/cfg/expression/GoCollectionAccess.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
import it.unive.lisa.analysis.nonrelational.value.NonRelationalValueDomain;
1313
import it.unive.lisa.analysis.nonrelational.value.ValueEnvironment;
1414
import it.unive.lisa.interprocedural.InterproceduralAnalysis;
15+
import it.unive.lisa.program.Global;
1516
import it.unive.lisa.program.SourceCodeLocation;
17+
import it.unive.lisa.program.Unit;
1618
import it.unive.lisa.program.cfg.CFG;
1719
import it.unive.lisa.program.cfg.statement.BinaryExpression;
1820
import it.unive.lisa.program.cfg.statement.Expression;
1921
import it.unive.lisa.program.cfg.statement.Statement;
22+
import it.unive.lisa.program.cfg.statement.global.AccessGlobal;
23+
import it.unive.lisa.program.cfg.statement.global.AccessInstanceGlobal;
2024
import it.unive.lisa.symbolic.SymbolicExpression;
2125
import it.unive.lisa.symbolic.heap.AccessChild;
2226
import it.unive.lisa.symbolic.heap.HeapDereference;
@@ -25,6 +29,7 @@
2529
import it.unive.lisa.symbolic.value.Identifier;
2630
import it.unive.lisa.symbolic.value.PushAny;
2731
import it.unive.lisa.symbolic.value.ValueExpression;
32+
import it.unive.lisa.symbolic.value.Variable;
2833
import it.unive.lisa.type.Type;
2934
import it.unive.lisa.type.Untyped;
3035

@@ -78,6 +83,14 @@ public <A extends AbstractState<A>> AnalysisState<A> fwdBinarySemantics(Interpro
7883
if (right instanceof Tainted)
7984
return state.smallStepSemantics(right, this);
8085

86+
if(left instanceof Variable) {
87+
Unit unit = this.getProgram().getUnit(left.toString());
88+
if(unit != null) {
89+
Global global = unit.getGlobal(right.toString());
90+
91+
return new AccessGlobal(getCFG(), getLocation(), unit, global).forwardSemantics(state, interprocedural, expressions);
92+
}
93+
}
8194

8295
SymbolicExpression inner;
8396
if (left instanceof HeapReference)

go-lisa/src/main/java/it/unive/golisa/cfg/runtime/encoding/base64/function/DecodeString.java

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import it.unive.lisa.program.cfg.CodeMemberDescriptor;
2222
import it.unive.lisa.program.cfg.NativeCFG;
2323
import it.unive.lisa.program.cfg.Parameter;
24+
import it.unive.lisa.program.cfg.statement.BinaryExpression;
2425
import it.unive.lisa.program.cfg.statement.Expression;
2526
import it.unive.lisa.program.cfg.statement.PluggableStatement;
2627
import it.unive.lisa.program.cfg.statement.Statement;
@@ -45,7 +46,8 @@ public class DecodeString extends NativeCFG {
4546
* @param unit the unit to which this native cfg belongs to
4647
*/
4748
public DecodeString(CodeLocation location, CompilationUnit unit) {
48-
super(new CodeMemberDescriptor(location, unit, false, "DecodeString", GoErrorType.INSTANCE,
49+
super(new CodeMemberDescriptor(location, unit, true, "DecodeString", GoErrorType.INSTANCE,
50+
new Parameter(location, "encoding", Encoding.getEncodingType(unit.getProgram())),
4951
new Parameter(location, "s", GoStringType.INSTANCE)),
5052
DecodeStringImpl.class);
5153
}
@@ -55,7 +57,7 @@ public DecodeString(CodeLocation location, CompilationUnit unit) {
5557
*
5658
* @author <a href="mailto:[email protected]">Luca Olivieri</a>
5759
*/
58-
public static class DecodeStringImpl extends UnaryExpression
60+
public static class DecodeStringImpl extends BinaryExpression
5961
implements PluggableStatement {
6062

6163
private Statement original;
@@ -65,23 +67,19 @@ public void setOriginatingStatement(Statement st) {
6567
original = st;
6668
}
6769

68-
@Override
69-
protected int compareSameClassAndParams(Statement o) {
70-
return 0; // nothing else to compare
71-
}
7270

7371
/**
7472
* Builds the pluggable statement.
7573
*
7674
* @param cfg the {@link CFG} where this pluggable statement lies
7775
* @param location the location where this pluggable statement is
7876
* defined
79-
* @param par the parameter
77+
* @param params the parameters
8078
*
8179
* @return the pluggable statement
8280
*/
83-
public static DecodeStringImpl build(CFG cfg, CodeLocation location, Expression par) {
84-
return new DecodeStringImpl(cfg, location, par);
81+
public static DecodeStringImpl build(CFG cfg, CodeLocation location, Expression[] params) {
82+
return new DecodeStringImpl(cfg, location, params[0], params[1]);
8583
}
8684

8785
/**
@@ -92,48 +90,58 @@ public static DecodeStringImpl build(CFG cfg, CodeLocation location, Expression
9290
* defined
9391
* @param par the par of this expression
9492
*/
95-
public DecodeStringImpl(CFG cfg, CodeLocation location, Expression par) {
96-
super(cfg, location, "DecodeStringImpl", GoErrorType.INSTANCE, par);
93+
public DecodeStringImpl(CFG cfg, CodeLocation location, Expression left, Expression right) {
94+
super(cfg, location, "DecodeStringImpl", GoErrorType.INSTANCE, left, right);
9795
}
9896

9997

10098
@Override
101-
public <A extends AbstractState<A>> AnalysisState<A> fwdUnarySemantics(
102-
InterproceduralAnalysis<A> interprocedural, AnalysisState<A> state, SymbolicExpression expr,
103-
StatementStore<A> expressions) throws SemanticException {
104-
Type sliceBytes= GoSliceType.getSliceOfBytes();
105-
106-
GoTupleType tupleType = GoTupleType.getTupleTypeOf(original.getLocation(), sliceBytes, GoErrorType.INSTANCE);
107-
108-
Annotations annots = new Annotations();
109-
if (original instanceof ResolvedCall)
110-
for (CodeMember target : ((ResolvedCall) original).getTargets())
111-
for (Annotation ann : target.getDescriptor().getAnnotations())
112-
annots.addAnnotation(ann);
113-
114-
115-
AnalysisState<A> pState = state.smallStepSemantics(expr, original);
116-
117-
ExpressionSet computeExprs = pState.getComputedExpressions();
118-
AnalysisState<A> ret = state.bottom();
119-
120-
for(SymbolicExpression exp : pState.getState().rewrite(computeExprs, original, state.getState())) {
121-
if(exp instanceof Identifier) {
122-
Identifier v = (Identifier) exp;
123-
for (Annotation ann : annots)
124-
v.addAnnotation(ann);
125-
}
126-
ret = ret.lub(GoTupleExpression.allocateTupleExpression(pState,
127-
annots,
128-
this,
129-
getLocation(),
130-
tupleType,
131-
exp,
132-
new Constant(GoErrorType.INSTANCE, "error", getLocation())));
133-
}
134-
135-
136-
return ret;
99+
public <A extends AbstractState<A>> AnalysisState<A> fwdBinarySemantics(
100+
InterproceduralAnalysis<A> interprocedural, AnalysisState<A> state, SymbolicExpression left,
101+
SymbolicExpression right, StatementStore<A> expressions) throws SemanticException {
102+
Type sliceBytes= GoSliceType.getSliceOfBytes();
103+
104+
GoTupleType tupleType = GoTupleType.getTupleTypeOf(original.getLocation(), sliceBytes, GoErrorType.INSTANCE);
105+
106+
Annotations annots = new Annotations();
107+
if (original instanceof ResolvedCall)
108+
for (CodeMember target : ((ResolvedCall) original).getTargets())
109+
for (Annotation ann : target.getDescriptor().getAnnotations())
110+
annots.addAnnotation(ann);
111+
112+
113+
AnalysisState<A> pState = state.smallStepSemantics(right, original);
114+
115+
ExpressionSet computeExprs = pState.getComputedExpressions();
116+
AnalysisState<A> ret = state.bottom();
117+
118+
for(SymbolicExpression exp : pState.getState().rewrite(computeExprs, original, state.getState())) {
119+
if(exp instanceof Identifier) {
120+
Identifier v = (Identifier) exp;
121+
for (Annotation ann : annots)
122+
v.addAnnotation(ann);
123+
}
124+
ret = ret.lub(GoTupleExpression.allocateTupleExpression(pState,
125+
annots,
126+
this,
127+
getLocation(),
128+
tupleType,
129+
exp,
130+
new Constant(GoErrorType.INSTANCE, "error", getLocation())));
131+
}
132+
133+
134+
return ret;
137135
}
136+
137+
138+
@Override
139+
protected int compareSameClassAndParams(Statement o) {
140+
// TODO Auto-generated method stub
141+
return 0;
142+
}
143+
144+
145+
138146
}
139147
}

go-lisa/src/main/java/it/unive/golisa/frontend/GoRuntimeLoader.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@
115115
import it.unive.golisa.cfg.runtime.time.type.Time;
116116
import it.unive.golisa.cfg.runtime.url.PathEscape;
117117
import it.unive.golisa.cfg.runtime.url.QueryEscape;
118+
import it.unive.golisa.cfg.type.GoStringType;
118119
import it.unive.golisa.cfg.type.composite.GoInterfaceType;
119120
import it.unive.golisa.cfg.type.composite.GoStructType;
120121
import it.unive.golisa.golang.util.GoLangAPISignatureMapper;
121122
import it.unive.golisa.golang.util.GoLangUtils;
122123
import it.unive.lisa.program.CodeUnit;
124+
import it.unive.lisa.program.Global;
123125
import it.unive.lisa.program.Program;
124126
import it.unive.lisa.program.SourceCodeLocation;
125127
import it.unive.lisa.type.Type;
@@ -325,11 +327,12 @@ private void loadBase64(Program program) {
325327

326328
register(Encoding.getEncodingType(program), program, GoInterfaceType::registerType);
327329
register(StdEncoding.getStdEncodingType(program), program, GoInterfaceType::registerType);
330+
331+
base64Unit.addGlobal(new Global(GoLangUtils.GO_RUNTIME_SOURCECODE_LOCATION, base64Unit, "StdEncoding",
332+
false, Encoding.getEncodingType(program)));
328333

329334
Encoding.registerMethods();
330335
StdEncoding.registerMethods();
331-
332-
333336
program.addUnit(base64Unit);
334337
}
335338

0 commit comments

Comments
 (0)