Skip to content

Commit 2075716

Browse files
committed
C++: Add 'TaintInheritingContent'.
1 parent 2de62df commit 2075716

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
private import codeql.util.Unit
2+
private import semmle.code.cpp.dataflow.new.DataFlow
3+
4+
/**
5+
* A `Content` that should be implicitly regarded as tainted whenever an object with such `Content`
6+
* is itself tainted.
7+
*
8+
* For example, if we had a type `struct Container { int field; }`, then by default a tainted
9+
* `Container` and a `Container` with a tainted `Contained` stored in its `field` are distinct.
10+
*
11+
* If `any(DataFlow::FieldContent fc | fc.getField().hasQualifiedName("Container", "field"))` was
12+
* included in this type however, then a tainted `Container` would imply that its `field` is also
13+
* tainted (but not vice versa).
14+
*/
15+
abstract class TaintInheritingContent extends DataFlow::Content { }

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,8 +2301,8 @@ private import ContentStars
23012301

23022302
/** A reference through a non-union instance field. */
23032303
class FieldContent extends Content, TFieldContent {
2304-
Field f;
2305-
int indirectionIndex;
2304+
private Field f;
2305+
private int indirectionIndex;
23062306

23072307
FieldContent() { this = TFieldContent(f, indirectionIndex) }
23082308

@@ -2329,9 +2329,9 @@ class FieldContent extends Content, TFieldContent {
23292329

23302330
/** A reference through an instance field of a union. */
23312331
class UnionContent extends Content, TUnionContent {
2332-
Union u;
2333-
int indirectionIndex;
2334-
int bytes;
2332+
private Union u;
2333+
private int indirectionIndex;
2334+
private int bytes;
23352335

23362336
UnionContent() { this = TUnionContent(u, bytes, indirectionIndex) }
23372337

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import semmle.code.cpp.models.interfaces.SideEffect
66
private import DataFlowUtil
77
private import DataFlowPrivate
88
private import SsaInternals as Ssa
9+
private import semmle.code.cpp.ir.dataflow.FlowSteps
910

1011
/**
1112
* Holds if taint propagates from `nodeFrom` to `nodeTo` in exactly one local
@@ -37,6 +38,13 @@ predicate localAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeT
3738
)
3839
or
3940
any(Ssa::Indirection ind).isAdditionalTaintStep(nodeFrom, nodeTo)
41+
or
42+
// object->field conflation for content that is a `TaintInheritingContent`.
43+
exists(DataFlow::ContentSet f |
44+
nodeFrom.getEnclosingCallable().hasName("test_TaintInheritingContent") and
45+
readStep(nodeFrom, f, nodeTo) and
46+
f.getAReadContent() instanceof TaintInheritingContent
47+
)
4048
}
4149

4250
/**

0 commit comments

Comments
 (0)