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.
65 lines
2.1 KiB
65 lines
2.1 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.builtins.InferTaint;
|
|
|
|
/** testing how the analysis handles missing/unknown code */
|
|
|
|
public abstract class UnknownCode {
|
|
|
|
native static Object nativeMethod(Object o);
|
|
|
|
abstract Object abstractMethod(Object o);
|
|
|
|
static interface Interface {
|
|
Object interfaceMethod(Object o);
|
|
}
|
|
|
|
static void propagateViaUnknownConstructorBad() {
|
|
String source = (String) InferTaint.inferSecretSource();
|
|
// we don't analyze the code for the core Java libraries, so this constructor will be unknown
|
|
String unknownConstructor = new String(source);
|
|
InferTaint.inferSensitiveSink(unknownConstructor);
|
|
}
|
|
|
|
static void propagateViaUnknownConstructorOk() {
|
|
String unknownConstructor = new String("");
|
|
InferTaint.inferSensitiveSink(unknownConstructor);
|
|
}
|
|
|
|
void propagateViaUnknownCodeOk(Interface i) {
|
|
Object notASource = new Object();
|
|
Object launderedSource1 = nativeMethod(notASource);
|
|
Object launderedSource2 = abstractMethod(launderedSource1);
|
|
Object launderedSource3 = i.interfaceMethod(launderedSource2);
|
|
InferTaint.inferSensitiveSink(launderedSource3);
|
|
}
|
|
|
|
static void FN_propagateViaInterfaceCodeBad(Interface i) {
|
|
Object source = InferTaint.inferSecretSource();
|
|
Object launderedSource = i.interfaceMethod(source);
|
|
InferTaint.inferSensitiveSink(launderedSource);
|
|
}
|
|
|
|
void FN_propagateViaUnknownNativeCodeBad() {
|
|
Object source = InferTaint.inferSecretSource();
|
|
Object launderedSource = nativeMethod(source);
|
|
InferTaint.inferSensitiveSink(launderedSource);
|
|
}
|
|
|
|
static void FN_propagateViaUnknownAbstractCodeBad() {
|
|
Object source = InferTaint.inferSecretSource();
|
|
Object launderedSource = nativeMethod(source);
|
|
InferTaint.inferSensitiveSink(launderedSource);
|
|
}
|
|
|
|
}
|