Skip to content

Commit 89e842b

Browse files
committed
finilize tests for zlib
1 parent f97b103 commit 89e842b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module DecompressionTaintConfig implements DataFlow::ConfigSig {
2222

2323
predicate isSink(DataFlow::Node sink) {
2424
exists(FunctionCall fc, DecompressionFunction f | fc.getTarget() = f |
25-
fc.getArgument(f.getArchiveParameterIndex()) = sink.asExpr()
25+
fc.getArgument(f.getArchiveParameterIndex()) = [sink.asExpr(), sink.asIndirectExpr()]
2626
)
2727
}
2828

cpp/ql/src/experimental/query-tests/Security/CWE/CWE-409/ZlibUncompress.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ import DecompressionBomb
1313
class UncompressFunction extends DecompressionFunction {
1414
UncompressFunction() { this.hasGlobalName(["uncompress", "uncompress2"]) }
1515

16-
override int getArchiveParameterIndex() { result = 0 }
16+
override int getArchiveParameterIndex() { result = 2 }
1717
}

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-409/zlibTest.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#define Z_NULL 0
32
# define FAR
43
typedef unsigned char Byte;
@@ -145,9 +144,32 @@ int UnsafeGzgets(char *fileName) {
145144
return 0;
146145
}
147146

147+
typedef unsigned long uLong;
148+
typedef long unsigned int size_t;
149+
typedef uLong uLongf;
150+
typedef unsigned char Bytef;
151+
#define Z_OK 0
152+
153+
int uncompress(Bytef *dest, uLongf *destLen,
154+
const Bytef *source, uLong sourceLen) { return 0; }
155+
156+
bool InflateString(const unsigned char *input, const unsigned char *output, size_t output_length) {
157+
uLong source_length;
158+
source_length = (uLong) 500;
159+
uLong destination_length;
160+
destination_length = (uLong) output_length;
161+
162+
int result = uncompress((Bytef *) output, &destination_length,
163+
(Bytef *) input, source_length);
164+
165+
return result == Z_OK;
166+
}
167+
148168
int main(int argc, char **argv) {
149169
UnsafeGzfread(argv[2]);
150170
UnsafeGzgets(argv[2]);
151171
UnsafeInflate(argv[2]);
152172
UnsafeGzread(argv[2]);
173+
const unsigned char *output;
174+
InflateString(reinterpret_cast<const unsigned char *>(argv[1]), output, 1024 * 1024 * 1024);
153175
}

0 commit comments

Comments
 (0)