Skip to content

Commit 4a1bf95

Browse files
committed
C++: Expose a public memset model and use it in the exposure queries.
1 parent e8c18a3 commit 4a1bf95

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

cpp/ql/lib/semmle/code/cpp/models/implementations/Memset.qll

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import semmle.code.cpp.models.interfaces.DataFlow
99
import semmle.code.cpp.models.interfaces.Alias
1010
import semmle.code.cpp.models.interfaces.SideEffect
1111

12-
/**
13-
* The standard function `memset` and its assorted variants
14-
*/
15-
private class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction,
12+
private class MemsetFunctionModel extends ArrayFunction, DataFlowFunction, AliasFunction,
1613
SideEffectFunction
1714
{
18-
MemsetFunction() {
15+
MemsetFunctionModel() {
1916
this.hasGlobalOrStdOrBslName("memset")
2017
or
2118
this.hasGlobalOrStdName("wmemset")
2219
or
23-
this.hasGlobalName([bzero(), "__builtin_memset", "__builtin_memset_chk"])
20+
this.hasGlobalName([
21+
bzero(), "__builtin_memset", "__builtin_memset_chk", "RtlZeroMemory", "RtlSecureZeroMemory"
22+
])
2423
}
2524

2625
override predicate hasArrayOutput(int bufParam) { bufParam = 0 }
@@ -60,3 +59,8 @@ private class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunct
6059
}
6160

6261
private string bzero() { result = ["bzero", "explicit_bzero"] }
62+
63+
/**
64+
* The standard function `memset` and its assorted variants
65+
*/
66+
class MemsetFunction extends Function instanceof MemsetFunctionModel { }

cpp/ql/src/Security/CWE/CWE-497/ExposedSystemData.ql

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import cpp
1616
import semmle.code.cpp.ir.dataflow.TaintTracking
1717
import semmle.code.cpp.models.interfaces.FlowSource
18+
import semmle.code.cpp.models.implementations.Memset
1819
import ExposedSystemData::PathGraph
1920
import SystemData
2021

@@ -28,6 +29,10 @@ module ExposedSystemDataConfig implements DataFlow::ConfigSig {
2829
fc.getArgument(arg).getAChild*() = sink.asIndirectExpr()
2930
)
3031
}
32+
33+
predicate isBarrier(DataFlow::Node node) {
34+
node.asIndirectArgument() = any(MemsetFunction func).getACallToThisFunction().getAnArgument()
35+
}
3136
}
3237

3338
module ExposedSystemData = TaintTracking::Global<ExposedSystemDataConfig>;

cpp/ql/src/Security/CWE/CWE-497/PotentiallyExposedSystemData.ql

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import cpp
2828
import semmle.code.cpp.ir.dataflow.TaintTracking
2929
import semmle.code.cpp.models.interfaces.FlowSource
3030
import semmle.code.cpp.security.OutputWrite
31+
import semmle.code.cpp.models.implementations.Memset
3132
import PotentiallyExposedSystemData::PathGraph
3233
import SystemData
3334

@@ -49,6 +50,10 @@ module PotentiallyExposedSystemDataConfig implements DataFlow::ConfigSig {
4950
else child = sink.asExpr()
5051
)
5152
}
53+
54+
predicate isBarrier(DataFlow::Node node) {
55+
node.asIndirectArgument() = any(MemsetFunction func).getACallToThisFunction().getAnArgument()
56+
}
5257
}
5358

5459
module PotentiallyExposedSystemData = TaintTracking::Global<PotentiallyExposedSystemDataConfig>;

0 commit comments

Comments
 (0)