forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jketema/amammad-cpp-bombs
Cleanup cpp bombs
- Loading branch information
Showing
29 changed files
with
522 additions
and
1,230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
cpp/ql/src/experimental/Security/CWE/CWE-409/ZlibInflator.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* https://www.zlib.net/ | ||
*/ | ||
|
||
import cpp | ||
import DecompressionBomb | ||
|
||
/** | ||
* The `inflate` and `inflateSync` functions are used in flow sink. | ||
* | ||
* `inflate(z_stream strm, int flush)` | ||
* | ||
* `inflateSync(z_stream strm)` | ||
*/ | ||
class InflateFunction extends DecompressionFunction { | ||
InflateFunction() { this.hasGlobalName(["inflate", "inflateSync"]) } | ||
|
||
override int getArchiveParameterIndex() { result = 0 } | ||
} | ||
|
||
/** | ||
* The `next_in` member of a `z_stream` variable is used in a flow steps. | ||
*/ | ||
class NextInMemberStep extends DecompressionFlowStep { | ||
NextInMemberStep() { this = "NextInMemberStep" } | ||
|
||
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { | ||
exists(Variable nextInVar, VariableAccess zStreamAccess | | ||
nextInVar.getDeclaringType().hasName("z_stream") and | ||
nextInVar.hasName("next_in") and | ||
zStreamAccess.getType().hasName("z_stream") | ||
| | ||
nextInVar.getAnAccess().getQualifier().(VariableAccess).getTarget() = | ||
zStreamAccess.getTarget() and | ||
node1.asIndirectExpr() = nextInVar.getAnAssignedValue() and | ||
node2.asExpr() = zStreamAccess | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
*/ | ||
|
||
import cpp | ||
import semmle.code.cpp.ir.dataflow.TaintTracking | ||
import DecompressionBomb | ||
|
||
/** | ||
|
15 changes: 15 additions & 0 deletions
15
cpp/ql/src/experimental/Security/CWE/CWE-409/example_bad.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "zlib.h" | ||
|
||
void UnsafeGzread(gzFile inFileZ) { | ||
const int BUFFER_SIZE = 8192; | ||
unsigned char unzipBuffer[BUFFER_SIZE]; | ||
unsigned int unzippedBytes; | ||
while (true) { | ||
unzippedBytes = gzread(inFileZ, unzipBuffer, BUFFER_SIZE); | ||
if (unzippedBytes <= 0) { | ||
break; | ||
} | ||
|
||
// process buffer | ||
} | ||
} |
Oops, something went wrong.