You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.5 KiB

/*
* 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);
}
void viaNestedFieldBad1(Obj obj) {
obj.g.f = InferTaint.inferSecretSource();
InferTaint.inferSensitiveSink(obj.g.f);
}
void viaNestedFieldBad2() {
Obj obj = new Obj();
obj.g = new Obj();
obj.g.f = InferTaint.inferSecretSource();
InferTaint.inferSensitiveSink(obj.g.f);
}
/** 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 soundly handle aliasing to get these examples
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);
}
}