Skip to content

Commit

Permalink
remove more unused imports, add tests for zstd, add flow steps for zstd
Browse files Browse the repository at this point in the history
zstd is not finilized
  • Loading branch information
am0o0 committed Sep 3, 2024
1 parent 4fc971d commit 81283d5
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import cpp
import semmle.code.cpp.ir.dataflow.TaintTracking
import semmle.code.cpp.commons.File
import DecompressionBomb

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import cpp
import semmle.code.cpp.ir.dataflow.TaintTracking
import semmle.code.cpp.security.FlowSources
import semmle.code.cpp.commons.File
import DecompressionBomb

module DecompressionTaintConfig implements DataFlow::ConfigSig {
Expand Down
43 changes: 31 additions & 12 deletions cpp/ql/src/experimental/query-tests/Security/CWE/CWE-409/ZSTD.qll
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,63 @@ import DecompressionBomb
/**
* The `ZSTD_decompress` function is used in flow sink.
*/
class ZSTDDecompressFunction extends DecompressionFunction {
ZSTDDecompressFunction() { this.hasGlobalName(["ZSTD_decompress"]) }
class ZstdDecompressFunction extends DecompressionFunction {
ZstdDecompressFunction() { this.hasGlobalName(["ZSTD_decompress"]) }

override int getArchiveParameterIndex() { result = 2 }
}

/**
* The `ZSTD_decompressDCtx` function is used in flow sink.
*/
class ZSTDDecompressDCtxFunction extends DecompressionFunction {
ZSTDDecompressDCtxFunction() { this.hasGlobalName(["ZSTD_decompressDCtx"]) }
class ZstdDecompressDctxFunction extends DecompressionFunction {
ZstdDecompressDctxFunction() { this.hasGlobalName(["ZSTD_decompressDCtx"]) }

override int getArchiveParameterIndex() { result = 3 }
}

/**
* The `ZSTD_decompressStream` function is used in flow sink.
*/
class ZSTDDecompressStreamFunction extends DecompressionFunction {
ZSTDDecompressStreamFunction() { this.hasGlobalName(["ZSTD_decompressStream"]) }
class ZstdDecompressStreamFunction extends DecompressionFunction {
ZstdDecompressStreamFunction() { this.hasGlobalName(["ZSTD_decompressStream"]) }

override int getArchiveParameterIndex() { result = 2 }
}

/**
* The `ZSTD_decompress_usingDDict` function is used in flow sink.
*/
class ZSTDDecompressUsingDictFunction extends DecompressionFunction {
ZSTDDecompressUsingDictFunction() { this.hasGlobalName(["ZSTD_decompress_usingDDict"]) }
class ZstdDecompressUsingDdictFunction extends DecompressionFunction {
ZstdDecompressUsingDdictFunction() { this.hasGlobalName(["ZSTD_decompress_usingDDict"]) }

override int getArchiveParameterIndex() { result = 3 }
}

/**
* The `ZSTD_decompress_usingDDict` function is used in flow sink.
* The `fopen_orDie` function as a flow step.
*/
class ZSTDDecompressUsingDDictFunction extends DecompressionFunction {
ZSTDDecompressUsingDDictFunction() { this.hasGlobalName(["ZSTD_decompress_usingDDict"]) }
class FopenOrDieFunction extends DecompressionFlowStep {
FopenOrDieFunction() { this.hasGlobalName("fopen_orDie") }

override int getArchiveParameterIndex() { result = 3 }
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
exists(FunctionCall fc | fc.getTarget() = this |
node1.asIndirectExpr() = fc.getArgument(0) and
node2.asExpr() = fc
)
}
}

/**
* The `fread_orDie` function as a flow step.
*/
class FreadOrDieFunction extends DecompressionFlowStep {
FreadOrDieFunction() { this.hasGlobalName("fread_orDie") }

override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
exists(FunctionCall fc | fc.getTarget() = this |
node1.asIndirectExpr() = fc.getArgument(2) and
node2.asIndirectExpr() = fc.getArgument(0)
)
}
}
Loading

0 comments on commit 81283d5

Please sign in to comment.