Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec772fb

Browse files
author
Benjamin Muskalla
committed
Add support for qualifier flow
1 parent 32ef40c commit ec772fb

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

java/ql/src/utils/model-generator/CaptureSummaryModels.ql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,33 @@
44
* @id TBD
55
*/
66

7+
import java
8+
import ModelGeneratorUtils
9+
10+
string captureFlow(Callable api) { result = captureQualifierFlow(api) }
11+
12+
string captureQualifierFlow(Callable api) {
13+
exists(ReturnStmt rtn |
14+
rtn.getEnclosingCallable() = api and
15+
rtn.getResult() instanceof ThisAccess
16+
) and
17+
result = asValueModel(api, "Argument[-1]", "ReturnValue")
18+
}
19+
20+
// TODO: handle cases like Ticker
21+
// TODO: "com.google.common.base;Converter;true;convertAll;(Iterable);;Element of Argument[0];Element of ReturnValue;taint",
22+
// TODO: infer interface from multiple implementations? e.g. UriComponentsContributor
23+
// TODO: distinguish between taint and value flows. If we find a value flow, omit the taint flow
24+
class TargetAPI extends Callable {
25+
TargetAPI() {
26+
this.isPublic() and
27+
this.fromSource() and
28+
this.getDeclaringType().isPublic() and
29+
not this.getCompilationUnit().getFile().getAbsolutePath().matches("%src/test/%") and
30+
not this.getCompilationUnit().getFile().getAbsolutePath().matches("%src/guava-tests/%")
31+
}
32+
}
33+
34+
from TargetAPI api, string flow
35+
where flow = captureFlow(api)
36+
select flow order by flow
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java
2+
import semmle.code.java.dataflow.ExternalFlow
3+
4+
string isExtensible(RefType ref) { if ref.isFinal() then result = "false" else result = "true" }
5+
6+
bindingset[input, output]
7+
string asTaintModel(Callable api, string input, string output) {
8+
result = asSummaryModel(api, input, output, "taint")
9+
}
10+
11+
bindingset[input, output]
12+
string asValueModel(Callable api, string input, string output) {
13+
result = asSummaryModel(api, input, output, "value")
14+
}
15+
16+
bindingset[input, output, kind]
17+
string asSummaryModel(Callable api, string input, string output, string kind) {
18+
result =
19+
api.getCompilationUnit().getPackage().getName() + ";" //
20+
+ api.getDeclaringType().nestedName() + ";" //
21+
+ isExtensible(api.getDeclaringType()).toString() + ";" //
22+
+ api.getName() + ";" //
23+
+ paramsString(api) + ";" //
24+
+ /* ext + */ ";" //
25+
+ input + ";" //
26+
+ output + ";" //
27+
+ kind + ";" //
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| p;FluentAPI;false;returnsThis;(String);;Argument[-1];ReturnValue;value; |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package p;
2+
3+
public final class FluentAPI {
4+
5+
public FluentAPI returnsThis(String input) {
6+
return this;
7+
}
8+
9+
}

0 commit comments

Comments
 (0)