Reviewed By: cristianoc Differential Revision: D3824276 fbshipit-source-id: c412f17master
parent
c613820a98
commit
6ca990be8c
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package codetoanalyze.java.quandary;
|
||||
|
||||
import com.facebook.infer.models.InferTaint;
|
||||
|
||||
public class Fields {
|
||||
|
||||
static class Obj {
|
||||
Object f;
|
||||
Obj g;
|
||||
}
|
||||
|
||||
Object mFld;
|
||||
static Object sFld;
|
||||
|
||||
/** should report on these tests */
|
||||
|
||||
void instanceFieldBad() {
|
||||
this.mFld = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(this.mFld);
|
||||
}
|
||||
|
||||
void staticFieldBad() {
|
||||
sFld = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(sFld);
|
||||
}
|
||||
|
||||
void viaFieldBad1(Obj obj) {
|
||||
obj.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj.f);
|
||||
}
|
||||
|
||||
void viaFieldBad2() {
|
||||
Obj obj = new Obj();
|
||||
obj.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj.f);
|
||||
}
|
||||
|
||||
void viaFieldBad3() {
|
||||
Obj obj = new Obj();
|
||||
obj.f = InferTaint.inferSecretSource();
|
||||
Object src = obj.f;
|
||||
InferTaint.inferSensitiveSink(src);
|
||||
}
|
||||
|
||||
/** should not report on these tests */
|
||||
|
||||
void viaFieldOk1(Obj obj) {
|
||||
obj.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj);
|
||||
}
|
||||
|
||||
void viaFieldOk2() {
|
||||
Obj obj = new Obj();
|
||||
obj.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj);
|
||||
}
|
||||
|
||||
void viaFieldOk3(Obj obj) {
|
||||
obj.g.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj.g);
|
||||
}
|
||||
|
||||
void viaFieldOk3() {
|
||||
Obj obj = new Obj();
|
||||
obj.f = InferTaint.inferSecretSource();
|
||||
obj.g = new Obj();
|
||||
InferTaint.inferSensitiveSink(obj.g);
|
||||
}
|
||||
|
||||
void viaFieldStrongUpdateOk() {
|
||||
Obj obj = new Obj();
|
||||
obj.f = InferTaint.inferSecretSource();
|
||||
obj.f = null;
|
||||
InferTaint.inferSensitiveSink(obj.f);
|
||||
}
|
||||
|
||||
void viaNestedFieldOK1(Obj obj) {
|
||||
obj.g.f = InferTaint.inferSecretSource();
|
||||
obj.g.f = null;
|
||||
InferTaint.inferSensitiveSink(obj.g.f);
|
||||
}
|
||||
|
||||
void viaNestedFieldOK2(Obj obj) {
|
||||
obj.g.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj.g);
|
||||
}
|
||||
|
||||
void viaNestedFieldOK3(Obj obj) {
|
||||
obj.g.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj);
|
||||
}
|
||||
|
||||
void viaNestedFieldOK4() {
|
||||
Obj obj = new Obj();
|
||||
obj.g = new Obj();
|
||||
obj.g.f = InferTaint.inferSecretSource();
|
||||
obj.g.f = null;
|
||||
InferTaint.inferSensitiveSink(obj.g.f);
|
||||
}
|
||||
|
||||
/** an ideal analysis would report on these tests, but we currently do not */
|
||||
|
||||
// need to handle aliasing to get these examples
|
||||
// in the first few cases, this is due to intermediate pvar's introduced by Infer's translation
|
||||
|
||||
void FN_viaNestedFieldBad1(Obj obj) {
|
||||
obj.g.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj.g.f);
|
||||
}
|
||||
|
||||
void FN_viaNestedFieldBad2() {
|
||||
Obj obj = new Obj();
|
||||
obj.g = new Obj();
|
||||
obj.g.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj.g.f);
|
||||
}
|
||||
|
||||
void FN_aliasBad1() {
|
||||
Obj obj1 = new Obj();
|
||||
Obj obj2 = obj1;
|
||||
obj2.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj1.f);
|
||||
}
|
||||
|
||||
void FN_AliasBad2(Obj obj) {
|
||||
Obj x = obj.g;
|
||||
x.f = InferTaint.inferSecretSource();
|
||||
InferTaint.inferSensitiveSink(obj.g.f);
|
||||
}
|
||||
|
||||
// need to fix our widening in order to report on this
|
||||
|
||||
void FN_loopFieldBad(Obj obj, int i) {
|
||||
Obj loopObj = obj;
|
||||
while (i < 10) {
|
||||
loopObj.f = InferTaint.inferSecretSource();
|
||||
loopObj = loopObj.g;
|
||||
i++;
|
||||
}
|
||||
InferTaint.inferSensitiveSink(obj.g.g.f);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue