Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit b2d4e26

Browse files
committed
Taint underlying aggregates of protobuf messages when an element is written
For example, writing to a[b].c[d] taints 'a'.
1 parent 3d82308 commit b2d4e26

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

ql/src/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,21 @@ class ReadNode extends InstructionNode {
593593
/**
594594
* A data-flow node that reads the value of a field from a struct, or an element from an array, slice, map or string.
595595
*/
596-
class ReadFromAggregateNode extends ReadNode {
596+
abstract class ReadFromAggregateNode extends ReadNode {
597597
/** Gets the data-flow node representing the base from which the field or element is read. */
598598
abstract Node getBase();
599599
}
600600

601+
/**
602+
* Gets the data-flow node representing the bottom of a stack of zero or more `ReadFromAggregateNode`s.
603+
*
604+
* For example, in the expression a.b[c].d[e], this would return the dataflow node for the read from `a`.
605+
*/
606+
Node getUnderlyingNode(ReadNode read) {
607+
(result = read or result = read.(ReadFromAggregateNode).getBase+()) and
608+
not result instanceof ReadFromAggregateNode
609+
}
610+
601611
/**
602612
* A data-flow node that reads an element of an array, map, slice or string.
603613
*/

ql/src/semmle/go/frameworks/Protobuf.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ module Protobuf {
146146
}
147147

148148
/**
149-
* Additional taint step tainting a Message when taint is written to any of its fields.
149+
* Additional taint step tainting a Message when taint is written to any of its fields and/or elements.
150150
*/
151151
private class WriteMessageFieldStep extends TaintTracking::AdditionalTaintStep {
152152
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
153-
any(DataFlow::Write w)
154-
.writesField(succ.(DataFlow::PostUpdateNode).getPreUpdateNode(), getAMessageField(), pred)
153+
exists(DataFlow::ReadNode base | succ = DataFlow::getUnderlyingNode(base) |
154+
any(DataFlow::Write w).writesField(base, getAMessageField(), pred)
155+
)
155156
}
156157
}
157158
}

0 commit comments

Comments
 (0)