From 6121faf671f58d3c9e9bb57fada66ea85fea0aa5 Mon Sep 17 00:00:00 2001 From: Stephan Brandauer Date: Wed, 13 Sep 2023 14:11:50 +0200 Subject: [PATCH] Java: Automodel: fr mode: connect new endpoints with MaD models --- .../AutomodelFrameworkModeCharacteristics.qll | 22 +++++++++++++++++-- ...meworkModeExtractNegativeExamples.expected | 4 +++- .../java/io/File.java | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll b/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll index 1aaf7bec3a6..10c4b583dd7 100644 --- a/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll +++ b/java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll @@ -199,12 +199,20 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig { } predicate isSource(Endpoint e, string kind, string provenance) { - none() // TODO: implement + exists(string package, string type, string name, string signature, string ext, string output | + sourceSpec(e, package, type, name, signature, ext, output) and + ExternalFlow::sourceModel(package, type, _, name, [signature, ""], ext, output, kind, + provenance) + ) } predicate isNeutral(Endpoint e) { exists(string package, string type, string name, string signature | - sinkSpec(e, package, type, name, signature, _, _) and + ( + sinkSpec(e, package, type, name, signature, _, _) + or + sourceSpec(e, package, type, name, signature, _, _) + ) and ExternalFlow::neutralModel(package, type, name, [signature, ""], "sink", _) ) } @@ -218,6 +226,16 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig { input = e.getMaDInput() } + additional predicate sourceSpec( + Endpoint e, string package, string type, string name, string signature, string ext, + string output + ) { + e.getEnclosingCallable().hasQualifiedName(package, type, name) and + signature = ExternalFlow::paramsString(e.getEnclosingCallable()) and + ext = "" and + output = e.getMaDOutput() + } + /** * Gets the related location for the given endpoint. * diff --git a/java/ql/automodel/test/AutomodelFrameworkModeExtraction/AutomodelFrameworkModeExtractNegativeExamples.expected b/java/ql/automodel/test/AutomodelFrameworkModeExtraction/AutomodelFrameworkModeExtractNegativeExamples.expected index f22421735e9..f25088b17ac 100644 --- a/java/ql/automodel/test/AutomodelFrameworkModeExtraction/AutomodelFrameworkModeExtractNegativeExamples.expected +++ b/java/ql/automodel/test/AutomodelFrameworkModeExtraction/AutomodelFrameworkModeExtractNegativeExamples.expected @@ -1,2 +1,4 @@ -| java/io/File.java:4:9:4:17 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:9:4:17 | compareTo | MethodDoc | java/io/File.java:4:9:4:17 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://:1:1:1:1 | | output | file://this:1:1:1:1 | this | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType | +| java/io/File.java:4:16:4:24 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://ReturnValue:1:1:1:1 | ReturnValue | output | file://:1:1:1:1 | | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType | +| java/io/File.java:4:16:4:24 | compareTo | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:4:16:4:24 | compareTo | MethodDoc | java/io/File.java:4:16:4:24 | compareTo | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[this]:1:1:1:1 | Argument[this] | input | file://:1:1:1:1 | | output | file://this:1:1:1:1 | this | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType | +| java/io/File.java:5:9:5:21 | pathname | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://:1:1:1:1 | | input | file://Parameter[0]:1:1:1:1 | Parameter[0] | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sourceModel:1:1:1:1 | sourceModel | extensibleType | | java/io/File.java:5:9:5:21 | pathname | known non-sink\nrelated locations: $@, $@.\nmetadata: $@, $@, $@, $@, $@, $@, $@. | java/io/File.java:5:9:5:21 | pathname | MethodDoc | java/io/File.java:5:9:5:21 | pathname | ClassDoc | file://java.io:1:1:1:1 | java.io | package | file://File:1:1:1:1 | File | type | file://true:1:1:1:1 | true | subtypes | file://compareTo:1:1:1:1 | compareTo | name | file://(File):1:1:1:1 | (File) | signature | file://Argument[0]:1:1:1:1 | Argument[0] | input | file://:1:1:1:1 | | output | file://pathname:1:1:1:1 | pathname | parameterName | file://sinkModel:1:1:1:1 | sinkModel | extensibleType | diff --git a/java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/io/File.java b/java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/io/File.java index fa812d47efd..019faa74537 100644 --- a/java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/io/File.java +++ b/java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/io/File.java @@ -1,9 +1,9 @@ package java.io; public class File { - int compareTo( // `this` is a negative example - this is modeled as a neutral model + public int compareTo( // `this` is a negative example - this is modeled as a neutral model File pathname // negative example - this is modeled as a neutral model ) { return 0; - } + } // also a negative example for ReturnValue source }