Skip to content

Commit 2369b18

Browse files
committed
C++: Make additional flow steps more uniform
1 parent 8fe0d0a commit 2369b18

File tree

7 files changed

+41
-34
lines changed

7 files changed

+41
-34
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-409/DecompressionBomb.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ abstract class DecompressionFunction extends Function {
1818
/**
1919
* The Decompression Flow Steps, extend this class to define new decompression sinks.
2020
*/
21-
abstract class DecompressionFlowStep extends Function {
21+
abstract class DecompressionFlowStep extends string {
22+
bindingset[this]
23+
DecompressionFlowStep() { any() }
24+
2225
abstract predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2);
2326
}

cpp/ql/src/experimental/Security/CWE/CWE-409/DecompressionBombs.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ module DecompressionTaintConfig implements DataFlow::ConfigSig {
2626
predicate isSink(DataFlow::Node sink) { isSink(_, sink) }
2727

2828
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
29-
any(DecompressionFlowStep f).isAdditionalFlowStep(node1, node2) or
30-
nextInAdditionalFlowStep(node1, node2)
29+
any(DecompressionFlowStep s).isAdditionalFlowStep(node1, node2)
3130
}
3231
}
3332

cpp/ql/src/experimental/Security/CWE/CWE-409/LibArchive.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ class Archive_read_data_block extends DecompressionFunction {
2020
/**
2121
* The `archive_read_open_filename` function as a flow step.
2222
*/
23-
class ReadOpenFunction extends DecompressionFlowStep {
24-
ReadOpenFunction() { this.hasGlobalName("archive_read_open_filename") }
23+
class ReadOpenFunctionStep extends DecompressionFlowStep {
24+
ReadOpenFunctionStep() { this = "ReadOpenFunction"}
2525

2626
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
27-
exists(FunctionCall fc | fc.getTarget() = this |
27+
exists(FunctionCall fc | fc.getTarget().hasGlobalName("archive_read_open_filename") |
2828
node1.asIndirectExpr() = fc.getArgument(1) and
2929
node2.asIndirectExpr() = fc.getArgument(0)
3030
)

cpp/ql/src/experimental/Security/CWE/CWE-409/MiniZip.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class UnzOpenFunction extends DecompressionFunction {
4242
/**
4343
* The `mz_zip_reader_open_file` and `mz_zip_reader_open_file_in_memory` functions as a flow step.
4444
*/
45-
class ReaderOpenFunction extends DecompressionFlowStep {
46-
ReaderOpenFunction() {
47-
this.hasGlobalName(["mz_zip_reader_open_file_in_memory", "mz_zip_reader_open_file"])
48-
}
45+
class ReaderOpenFunctionStep extends DecompressionFlowStep {
46+
ReaderOpenFunctionStep() { this = "ReaderOpenFunctionStep" }
4947

5048
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
51-
exists(FunctionCall fc | fc.getTarget() = this |
49+
exists(FunctionCall fc |
50+
fc.getTarget().hasGlobalName(["mz_zip_reader_open_file_in_memory", "mz_zip_reader_open_file"])
51+
|
5252
node1.asIndirectExpr() = fc.getArgument(1) and
5353
node2.asIndirectExpr() = fc.getArgument(0)
5454
)

cpp/ql/src/experimental/Security/CWE/CWE-409/ZSTD.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ class ZstdDecompressUsingDdictFunction extends DecompressionFunction {
4444
/**
4545
* The `fopen_orDie` function as a flow step.
4646
*/
47-
class FopenOrDieFunction extends DecompressionFlowStep {
48-
FopenOrDieFunction() { this.hasGlobalName("fopen_orDie") }
47+
class FopenOrDieFunctionStep extends DecompressionFlowStep {
48+
FopenOrDieFunctionStep() { this = "FopenOrDieFunctionStep" }
4949

5050
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
51-
exists(FunctionCall fc | fc.getTarget() = this |
51+
exists(FunctionCall fc | fc.getTarget().hasGlobalName("fopen_orDie") |
5252
node1.asIndirectExpr() = fc.getArgument(0) and
5353
node2.asExpr() = fc
5454
)
@@ -58,11 +58,11 @@ class FopenOrDieFunction extends DecompressionFlowStep {
5858
/**
5959
* The `fread_orDie` function as a flow step.
6060
*/
61-
class FreadOrDieFunction extends DecompressionFlowStep {
62-
FreadOrDieFunction() { this.hasGlobalName("fread_orDie") }
61+
class FreadOrDieFunctionStep extends DecompressionFlowStep {
62+
FreadOrDieFunctionStep() { this = "FreadOrDieFunctionStep" }
6363

6464
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
65-
exists(FunctionCall fc | fc.getTarget() = this |
65+
exists(FunctionCall fc | fc.getTarget().hasGlobalName("fread_orDie") |
6666
node1.asIndirectExpr() = fc.getArgument(2) and
6767
node2.asIndirectExpr() = fc.getArgument(0)
6868
)

cpp/ql/src/experimental/Security/CWE/CWE-409/ZlibGzopen.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class GzReadFunction extends DecompressionFunction {
4343
*
4444
* `gzdopen(int fd, const char *mode)`
4545
*/
46-
class GzdopenFunction extends DecompressionFlowStep {
47-
GzdopenFunction() { this.hasGlobalName("gzdopen") }
46+
class GzdopenFunctionStep extends DecompressionFlowStep {
47+
GzdopenFunctionStep() { this = "GzdopenFunctionStep" }
4848

4949
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
50-
exists(FunctionCall fc | fc.getTarget() = this |
50+
exists(FunctionCall fc | fc.getTarget().hasGlobalName("gzdopen") |
5151
node1.asExpr() = fc.getArgument(0) and
5252
node2.asExpr() = fc
5353
)
@@ -59,11 +59,11 @@ class GzdopenFunction extends DecompressionFlowStep {
5959
*
6060
* `gzopen(const char *path, const char *mode)`
6161
*/
62-
class GzopenFunction extends DecompressionFlowStep {
63-
GzopenFunction() { this.hasGlobalName("gzopen") }
62+
class GzopenFunctionStep extends DecompressionFlowStep {
63+
GzopenFunctionStep() { this = "GzopenFunctionStep" }
6464

6565
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
66-
exists(FunctionCall fc | fc.getTarget() = this |
66+
exists(FunctionCall fc | fc.getTarget().hasGlobalName("gzopen") |
6767
node1.asIndirectExpr() = fc.getArgument(0) and
6868
node2.asExpr() = fc
6969
)

cpp/ql/src/experimental/Security/CWE/CWE-409/ZlibInflator.qll

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@ class InflateFunction extends DecompressionFunction {
1919
}
2020

2121
/**
22-
* The `next_in` member of a `z_stream` variable is used in flow steps.
22+
* The `next_in` member of a `z_stream` variable is used in a flow steps.
2323
*/
24-
predicate nextInAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
25-
exists(Variable nextInVar, VariableAccess zStreamAccess |
26-
nextInVar.getDeclaringType().hasName("z_stream") and
27-
nextInVar.hasName("next_in") and
28-
zStreamAccess.getType().hasName("z_stream")
29-
|
30-
nextInVar.getAnAccess().getQualifier().(VariableAccess).getTarget() = zStreamAccess.getTarget() and
31-
node1.asIndirectExpr() = nextInVar.getAnAssignedValue() and
32-
node2.asExpr() = zStreamAccess
33-
)
24+
class NextInMemberStep extends DecompressionFlowStep {
25+
NextInMemberStep() { this = "NextInMemberStep" }
26+
27+
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
28+
exists(Variable nextInVar, VariableAccess zStreamAccess |
29+
nextInVar.getDeclaringType().hasName("z_stream") and
30+
nextInVar.hasName("next_in") and
31+
zStreamAccess.getType().hasName("z_stream")
32+
|
33+
nextInVar.getAnAccess().getQualifier().(VariableAccess).getTarget() =
34+
zStreamAccess.getTarget() and
35+
node1.asIndirectExpr() = nextInVar.getAnAssignedValue() and
36+
node2.asExpr() = zStreamAccess
37+
)
38+
}
3439
}

0 commit comments

Comments
 (0)