Skip to content

Commit 1ebd074

Browse files
author
Max Schaefer
committed
Fix treatment of void method calls.
1 parent 18e44b6 commit 1ebd074

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
239239
// Sanitizers are currently not modeled in MaD. TODO: check if this has large negative impact.
240240
predicate isSanitizer(Endpoint e, EndpointType t) {
241241
exists(t) and
242-
AutomodelJavaUtil::isUnexploitableType(e.asNode().getType())
242+
AutomodelJavaUtil::isUnexploitableType([
243+
// for most endpoints, we can get the type from the node
244+
e.asNode().getType(),
245+
// but not for calls to void methods, where we need to go via the AST
246+
e.asTop().(Expr).getType()
247+
])
243248
or
244249
t instanceof AutomodelEndpointTypes::PathInjectionSinkType and
245250
e.asNode() instanceof PathSanitizer::PathInjectionSanitizer

java/ql/automodel/test/AutomodelApplicationModeExtraction/Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void main(String[] args) throws Exception {
1818
AtomicReference<String> reference = new AtomicReference<>(); // uninteresting (parameterless constructor)
1919
reference.set( // $ sinkModel=set(Object):Argument[this]
2020
args[0] // not a sink candidate (modeled as a flow step)
21-
); // $ sourceModel=set(Object):ReturnValue
21+
); // not a source candidate (return type is void)
2222
}
2323

2424
public static void callSupplier(Supplier<String> supplier) {
@@ -92,7 +92,7 @@ public static void FilesListExample(Path p) throws Exception {
9292

9393
Files.delete(
9494
p // $ sinkModel=delete(Path):Argument[0]
95-
); // $ SPURIOUS: sourceModel=delete(Path):ReturnValue
95+
); // not a source candidate (return type is void)
9696

9797
Files.deleteIfExists(
9898
p // $ sinkModel=deleteIfExists(Path):Argument[0]

0 commit comments

Comments
 (0)