-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13982 from aschackmull/dataflow/typeflow-calledge…
…-pruning Dataflow: Add type-based call-edge pruning.
- Loading branch information
Showing
19 changed files
with
919 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
java/ql/test/library-tests/dataflow/typeflow-dispatch/A.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import java.util.*; | ||
import java.util.function.*; | ||
|
||
public class A { | ||
static String source(String tag) { return null; } | ||
|
||
static void sink(Object o) { } | ||
|
||
interface MyConsumer { | ||
void run(Object o); | ||
} | ||
|
||
void apply(MyConsumer f, Object x) { | ||
f.run(x); | ||
} | ||
|
||
void apply_wrap(MyConsumer f, Object x) { | ||
apply(f, x); | ||
} | ||
|
||
void testLambdaDispatch1() { | ||
apply_wrap(x -> { sink(x); }, source("A")); // $ hasValueFlow=A | ||
apply_wrap(x -> { sink(x); }, null); // no flow | ||
apply_wrap(x -> { }, source("B")); | ||
apply_wrap(x -> { }, null); | ||
} | ||
|
||
void forEach_wrap(List<Object> l, Consumer<Object> f) { | ||
l.forEach(f); | ||
} | ||
|
||
void testLambdaDispatch2() { | ||
List<Object> tainted = new ArrayList<>(); | ||
tainted.add(source("L")); | ||
List<Object> safe = new ArrayList<>(); | ||
forEach_wrap(safe, x -> { sink(x); }); // no flow | ||
forEach_wrap(tainted, x -> { sink(x); }); // $ hasValueFlow=L | ||
} | ||
|
||
static class TaintedClass { | ||
public String toString() { return source("TaintedClass"); } | ||
} | ||
|
||
static class SafeClass { | ||
public String toString() { return "safe"; } | ||
} | ||
|
||
String convertToString(Object o) { | ||
return o.toString(); | ||
} | ||
|
||
String convertToString_wrap(Object o) { | ||
return convertToString(o); | ||
} | ||
|
||
void testToString1() { | ||
String unused = convertToString_wrap(new TaintedClass()); | ||
sink(convertToString_wrap(new SafeClass())); // no flow | ||
} | ||
} |
Empty file.
2 changes: 2 additions & 0 deletions
2
java/ql/test/library-tests/dataflow/typeflow-dispatch/test.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import TestUtilities.InlineFlowTest | ||
import DefaultFlowTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: majorAnalysis | ||
--- | ||
* Added support for type-based call edge pruning. This removes data flow call edges that are incompatible with the set of flow paths that reach it based on type information. This improves dispatch precision for constructs like lambdas, `Object.toString()` calls, and the visitor pattern. For now this is only enabled for Java and C#. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.