Skip to content

Commit b634770

Browse files
Add qtil.java
1 parent c0a3640 commit b634770

18 files changed

Lines changed: 238 additions & 0 deletions

java/src/codeql-pack.lock.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies:
4+
codeql/dataflow:
5+
version: 1.1.6
6+
codeql/java-all:
7+
version: 4.2.1
8+
codeql/mad:
9+
version: 1.0.12
10+
codeql/rangeanalysis:
11+
version: 1.0.12
12+
codeql/regex:
13+
version: 1.0.12
14+
codeql/ssa:
15+
version: 1.0.12
16+
codeql/threat-models:
17+
version: 1.0.12
18+
codeql/tutorial:
19+
version: 1.0.12
20+
codeql/typeflow:
21+
version: 1.0.12
22+
codeql/typetracking:
23+
version: 1.0.12
24+
codeql/util:
25+
version: 1.0.12
26+
codeql/xml:
27+
version: 1.0.12
28+
compiled: false

java/src/qlpack.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: mfairhurst/qtil-java
2+
library: true
3+
warnOnImplicitThis: false
4+
version: 0.0.1
5+
license: MIT
6+
dependencies:
7+
codeql/java-all: '>=0.0.1 <8.0.0'
8+
mfairhurst/qtil: 0.0.1

java/src/qtil/Java.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Qtil {
2+
private import qtil.Qtil as Common
3+
// Importing qtil.Cpp should import all of Qtil.
4+
import Common::Qtil
5+
import qtil.java.ast.TwoOperands
6+
import qtil.java.format.QlFormat
7+
import qtil.java.graph.CustomPathProblem
8+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java as java
2+
import qtil.parameterization.SignatureTypes
3+
4+
/**
5+
* A module for dealing with pairs of exclusive operands in C++ ASTs.
6+
*
7+
* For instance, to find cases where one operand is an integer and the other is a constant, you
8+
* will want to to perform checks on each operand separately and consistently without worrying about
9+
* order. This module makes this common pattern easy to implement.
10+
*
11+
* This module takes two type parameters:
12+
* - `Operand`: the type of the operands (e.g. `Expr`)
13+
* - `HasOperands`: a type that has operands of type `Operand` (e.g. `BinaryExpr`)
14+
*
15+
* ```ql
16+
* // Using this module:
17+
* predicate myBinaryTestNew(BinaryExpr e) {
18+
* exists(TwoOperands<BinaryExpr>::Set set |
19+
* set.getOperation() = e and
20+
* set.someOperand().isInteger() and
21+
* set.otherOperand().isConstant()
22+
* )
23+
* }
24+
*
25+
* // Is roughly equivalent to:
26+
* predicate myBinaryTestOld(BinaryExpr e) {
27+
* exists(Expr a, Expr b |
28+
* e.getAnOperand() = a and
29+
* e.getAnOperand() = b and
30+
* a != b and
31+
* a.isInteger() and
32+
* b.isConstant()
33+
* )
34+
* }
35+
* ```
36+
*
37+
* Some caution about using this module: for each use, two `Set` objects exst. If you do not
38+
* properly constrain the usage of `someOperand()` and `otherOperand()`, then these members could
39+
* hold for different `Set`s. Therefore, `someOperand()` and `otherOperand()` may be the same
40+
* operand. This will not happen if the `Set` is properly constrained across the two member
41+
* invocations.
42+
*
43+
* ```ql
44+
* predicate bug(BinaryExpr e) {
45+
* // Bad: the two sets are not constrained to the same instance, therefore the operands not
46+
* // guaranteed to be different.
47+
* TwoOperands<BinaryExpr>::getASet(e).someOperand().isInteger() and
48+
* TwoOperands<BinaryExpr>::getASet(e).otherOperand().isConstant()
49+
* }
50+
* ```
51+
*/
52+
module TwoOperands<Signature<java::BinaryExpr>::Type BinOp> {
53+
private import qtil.ast.TwoOperands as Make
54+
import Make::TwoOperands<java::Expr, BinOp>
55+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
private import qtil.format.QLFormat
2+
private import java
3+
private import qtil.java.locations.Locatable
4+
5+
import QlFormat<Location, JavaLocatableConfig>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
private import qtil.locations.CustomPathProblem
2+
private import qtil.java.locations.Locatable
3+
private import java
4+
5+
// Import the Java specific configuration for making custom path problems.
6+
import PathProblem<Location, JavaLocatableConfig>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
private import qtil.locations.Locatable
2+
private import java
3+
4+
/**
5+
* A module to declare `Locatable`s specific to Java for use in other qtil modules.
6+
*/
7+
module JavaLocatableConfig implements LocatableConfig<Location> {
8+
class Locatable = Element;
9+
}

java/test/codeql-pack.lock.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies:
4+
codeql/dataflow:
5+
version: 1.1.6
6+
codeql/java-all:
7+
version: 4.2.1
8+
codeql/mad:
9+
version: 1.0.12
10+
codeql/rangeanalysis:
11+
version: 1.0.12
12+
codeql/regex:
13+
version: 1.0.12
14+
codeql/ssa:
15+
version: 1.0.12
16+
codeql/threat-models:
17+
version: 1.0.12
18+
codeql/tutorial:
19+
version: 1.0.12
20+
codeql/typeflow:
21+
version: 1.0.12
22+
codeql/typetracking:
23+
version: 1.0.12
24+
codeql/util:
25+
version: 1.0.12
26+
codeql/xml:
27+
version: 1.0.12
28+
compiled: false

java/test/qlpack.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: mfairhurst/qtil-java-test
2+
library: true
3+
warnOnImplicitThis: false
4+
version: 0.0.1
5+
license: MIT
6+
dependencies:
7+
mfairhurst/qtil-java: "*"
8+
extractor: java
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.java:6:12:6:16 | ... + ... | test.java:6:12:6:12 | a | test.java:6:16:6:16 | b |
2+
| test.java:7:12:7:16 | ... + ... | test.java:7:16:7:16 | a | test.java:7:12:7:12 | b |

0 commit comments

Comments
 (0)