diff --git a/java/ql/src/utils/model-generator/CaptureSourceModels.ql b/java/ql/src/utils/model-generator/CaptureSourceModels.ql index 9b380e2c3b7..9c14fe05c9c 100644 --- a/java/ql/src/utils/model-generator/CaptureSourceModels.ql +++ b/java/ql/src/utils/model-generator/CaptureSourceModels.ql @@ -29,7 +29,7 @@ class FromSourceConfiguration extends TaintTracking::Configuration { } } -// TODO: better way than rely on internals? +// TODO: better way than rely on internals to capture kind? cached predicate specificSourceNode(DataFlow::Node node, string output, string kind) { exists(InterpretNode n | Private::External::isSourceNode(n, output, kind) and n.asNode() = node) diff --git a/java/ql/src/utils/model-generator/CaptureSummaryModels.ql b/java/ql/src/utils/model-generator/CaptureSummaryModels.ql index 1d865aa825a..7ab4a5c73ff 100644 --- a/java/ql/src/utils/model-generator/CaptureSummaryModels.ql +++ b/java/ql/src/utils/model-generator/CaptureSummaryModels.ql @@ -130,10 +130,6 @@ predicate isRelevantType(Type t) { not t.(CollectionType).getElementType() instanceof BoxedType } -// TODO: "com.google.common.base;Converter;true;convertAll;(Iterable);;Element of Argument[0];Element of ReturnValue;taint", -// TODO: infer interface from multiple implementations? e.g. UriComponentsContributor -// TODO: distinguish between taint and value flows. If we find a value flow, omit the taint flow -// TODO: merge param->return value with param->parameter flow? from TargetAPI api, string flow where flow = captureFlow(api) select flow order by flow diff --git a/java/ql/src/utils/model-generator/ModelGeneratorUtils.qll b/java/ql/src/utils/model-generator/ModelGeneratorUtils.qll index d639897dbd7..9de2777cdef 100644 --- a/java/ql/src/utils/model-generator/ModelGeneratorUtils.qll +++ b/java/ql/src/utils/model-generator/ModelGeneratorUtils.qll @@ -69,7 +69,7 @@ string asSourceModel(Callable api, string output, string kind) { */ private string asPartialModel(Callable api) { result = - asModelName(api) + ";" // + typeAsSummaryModel(api) + ";" // + isExtensible(api.getDeclaringType()).toString() + ";" // + api.getName() + ";" // + paramsString(api) + ";" // @@ -80,12 +80,20 @@ private string asPartialModel(Callable api) { * Returns the appropriate type name for the model. Either the type * declaring the method or the supertype introducing the method. */ -private string asModelName(Callable api) { - if api.(Method).getASourceOverriddenMethod().fromSource() - then result = typeAsModel(api.(Method).getASourceOverriddenMethod().getDeclaringType()) +private string typeAsSummaryModel(Callable api) { + if exists(superImpl(api.(Method))) + then + superImpl(api.(Method)).fromSource() and + result = typeAsModel(superImpl(api.(Method)).getDeclaringType()) else result = typeAsModel(api.getDeclaringType()) } +Method superImpl(Method m) { + result = m.getAnOverride() and + not exists(result.getAnOverride()) and + not m instanceof ToStringMethod +} + private string typeAsModel(RefType type) { result = type.getCompilationUnit().getPackage().getName() + ";" + type.nestedName() } diff --git a/java/ql/test/utils/model-generator/p/AbstractImplOfExternalSPI.java b/java/ql/test/utils/model-generator/p/AbstractImplOfExternalSPI.java new file mode 100644 index 00000000000..05d2d2037fc --- /dev/null +++ b/java/ql/test/utils/model-generator/p/AbstractImplOfExternalSPI.java @@ -0,0 +1,13 @@ +package p; + +import java.io.File; +import java.io.FileFilter; + +public abstract class AbstractImplOfExternalSPI implements FileFilter { + + @Override + public boolean accept(File pathname) { + return false; + } + +} \ No newline at end of file diff --git a/java/ql/test/utils/model-generator/p/ImplOfExternalSPI.java b/java/ql/test/utils/model-generator/p/ImplOfExternalSPI.java new file mode 100644 index 00000000000..c16cdc544fb --- /dev/null +++ b/java/ql/test/utils/model-generator/p/ImplOfExternalSPI.java @@ -0,0 +1,19 @@ +package p; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +public class ImplOfExternalSPI extends AbstractImplOfExternalSPI { + + @Override + public boolean accept(File pathname) { + try { + Files.createFile(pathname.toPath()); + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + +} \ No newline at end of file diff --git a/java/ql/test/utils/model-generator/p/MultipleImpls.java b/java/ql/test/utils/model-generator/p/MultipleImpls.java index e7f80c76bb6..8824e7da3b2 100644 --- a/java/ql/test/utils/model-generator/p/MultipleImpls.java +++ b/java/ql/test/utils/model-generator/p/MultipleImpls.java @@ -1,9 +1,13 @@ package p; +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.nio.file.Files; import java.util.concurrent.Callable; public class MultipleImpls { - + public static interface Strategy { String doSomething(String value); } @@ -22,7 +26,7 @@ public class MultipleImpls { return null; } - } + } public static class Strat2 implements Strategy { private String foo;