Skip to content

Java: Initial CSV model generator#6664

Merged
bmuskalla merged 65 commits intogithub:mainfrom
bmuskalla:bmuskalla/modelGenerator
Nov 17, 2021
Merged

Java: Initial CSV model generator#6664
bmuskalla merged 65 commits intogithub:mainfrom
bmuskalla:bmuskalla/modelGenerator

Conversation

@bmuskalla
Copy link
Contributor

@bmuskalla bmuskalla commented Sep 10, 2021

Adds ability to generate flow summaries in CSV format given an existing library.
It supports detecting sinks/sources via propagation (so only existing sinks exposed through a new external API).

Usage is either:

java/ql/src/utils/model-generator/GenerateFlowModel.py <path-some-db> <shortname>

The resulting .qll CSV model written to codeql/java/ql/lib/semmle/code/java/frameworks/generated/<shortname>.qll

Examples (Guava, various Apache Commons projects)

Alternatively, you can run any of the queries directly:

  • CaptureSummaryModels.ql
  • CaptureSinkModels.ql
  • CaptureSourceModels.ql

Some initial stats (model as data rows)

Framework Already supported rows Newly generated rows Runtime
Commons IO 22 637 105s
Commons Codec 6 145 80s
Commons Lang 423 1361 96s
Commons Beanutils 0 517 106s
Guava 734 TBD TBD
JDK 5571 TBD1 TBD

Footnotes

  1. Counting only java. APIs 2

@bmuskalla bmuskalla added the Java label Sep 10, 2021
@bmuskalla bmuskalla force-pushed the bmuskalla/modelGenerator branch 3 times, most recently from e7c63ad to 96e085f Compare September 30, 2021 12:42
@bmuskalla bmuskalla dismissed a stale review via 48521e6 October 8, 2021 10:37
@bmuskalla bmuskalla force-pushed the bmuskalla/modelGenerator branch from 96e085f to 48521e6 Compare October 8, 2021 10:37
@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2021

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Java Standard Library,``java.*``,3,426,30,13,,,7,,,10
+    Java Standard Library,``java.*``,3,427,30,13,,,7,,,10
-    Totals,,143,5137,408,13,6,10,107,33,1,66
+    Totals,,143,5138,408,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- java.lang,,,50,,,,,,,,,,,,,,,,,,,,,41,9
+ java.lang,,,51,,,,,,,,,,,,,,,,,,,,,42,9

@bmuskalla bmuskalla force-pushed the bmuskalla/modelGenerator branch from 48521e6 to 0c6c082 Compare October 21, 2021 09:42
@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Java Standard Library,``java.*``,3,506,30,13,,,7,,,10
+    Java Standard Library,``java.*``,3,507,30,13,,,7,,,10
-    Totals,,143,5257,408,13,6,10,107,33,1,66
+    Totals,,143,5258,408,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- java.lang,,,50,,,,,,,,,,,,,,,,,,,,,41,9
+ java.lang,,,51,,,,,,,,,,,,,,,,,,,,,42,9

@bmuskalla
Copy link
Contributor Author

@hvitved @aschackmull It would be great to get some eyes on this. The queries themselves should be in a state we can discuss and I'll hold of further refinements until we have agreement on the general direction of them, as discussed. There is also 1 remaining TODO (which is causing the build to fail) around how to best access the models kind - once we're happy with that, I can re-sync the files and get the build to pass.
In the meantime, I'm working on being able to have a good diff between the generated and the existing models to further reviews.

@bmuskalla bmuskalla changed the title Java: Draft of CSV model generator Java: Initial CSV model generator Oct 21, 2021
source instanceof DataFlow::InstanceParameterNode
}

override predicate isSink(DataFlow::Node sink) { sink instanceof ReturnNodeExt }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add and not sink.(ReturnNode).asExpr().(ThisAccess).isOwnInstanceAccess().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not enough unfortunately. That misses the case when a return statements expression is a call to a fluent api itself (e.g. Joiner#merge(Joiner)

return add(...)

I've tried to move the predicates below into the configuration to restrict the nodes we look at. Let me know if you think there is a better way to handle this.

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Java Standard Library,``java.*``,3,523,30,13,,,7,,,10
+    Java Standard Library,``java.*``,3,524,30,13,,,7,,,10
-    Totals,,175,5368,431,13,6,10,107,33,1,66
+    Totals,,175,5369,431,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- java.lang,,,51,,,,,,,,,,,,,,,,,,,,,,41,10
+ java.lang,,,52,,,,,,,,,,,,,,,,,,,,,,42,10

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Java Standard Library,``java.*``,3,523,30,13,,,7,,,10
+    Java Standard Library,``java.*``,3,524,30,13,,,7,,,10
-    Totals,,175,5368,431,13,6,10,107,33,1,66
+    Totals,,175,5369,431,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- java.lang,,,51,,,,,,,,,,,,,,,,,,,,,,41,10
+ java.lang,,,52,,,,,,,,,,,,,,,,,,,,,,42,10

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged.

Click to show differences in coverage

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Java Standard Library,``java.*``,3,523,30,13,,,7,,,10
+    Java Standard Library,``java.*``,3,524,30,13,,,7,,,10
-    Totals,,175,5368,431,13,6,10,107,33,1,66
+    Totals,,175,5369,431,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- java.lang,,,51,,,,,,,,,,,,,,,,,,,,,,41,10
+ java.lang,,,52,,,,,,,,,,,,,,,,,,,,,,42,10

@bmuskalla
Copy link
Contributor Author

🥳

@bmuskalla bmuskalla merged commit 3c3a652 into github:main Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants