Java: tests for automodel application mode candidate extraction

This commit is contained in:
Stephan Brandauer
2023-07-21 14:41:29 +02:00
parent 18fe587e75
commit 2e89a11949
3 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
| Test.java:14:3:14:11 | reference | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@. | Test.java:14:3:14:24 | set(...) | CallContext | file://java.util.concurrent.atomic:1:1:1:1 | java.util.concurrent.atomic | package | file://AtomicReference:1:1:1:1 | AtomicReference | type | file://false:1:1:1:1 | false | subtypes | file://set:1:1:1:1 | set | name | file://(String):1:1:1:1 | (String) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input |
| Test.java:20:3:20:10 | supplier | command-injection, path-injection, request-forgery, sql-injection\nrelated locations: $@.\nmetadata: $@, $@, $@, $@, $@, $@. | Test.java:20:3:20:16 | get(...) | CallContext | file://java.util.function:1:1:1:1 | java.util.function | package | file://Supplier:1:1:1:1 | Supplier | type | file://true:1:1:1:1 | true | subtypes | file://get:1:1:1:1 | get | name | file://():1:1:1:1 | () | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input |

View File

@@ -0,0 +1 @@
Telemetry/AutomodelApplicationModeExtractCandidates.ql

View File

@@ -0,0 +1,36 @@
package com.github.codeql.test;
import java.io.InputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
class AutomodelApplicationModeExtractCandidates {
public static void main(String[] args) throws Exception {
AtomicReference<String> reference = new AtomicReference<>(); // uninteresting (parameterless constructor)
reference.set(args[0]); // arg[0] is not a candidate (modeled as value flow step)
// ^^^^^^ Argument[this] is a candidate (should no longer be, once a recent PR
// is merged)
}
public static void callSupplier(Supplier<String> supplier) {
supplier.get(); // Argument[this] is a candidate
}
public static void copyFiles(Path source, Path target, CopyOption option) throws Exception {
Files.copy(
source, // no candidate (modeled)
target, // no candidate (modeled)
option // no candidate (not modeled, but source and target are modeled)
);
}
public static InputStream getInputStream(Path openPath) throws Exception {
return Files.newInputStream(
openPath // no candidate (known sink)
);
}
}