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

Commit 3635d7d

Browse files
committed
Introduce and use writeComponent
1 parent 2a863fb commit 3635d7d

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

ql/src/semmle/go/controlflow/ControlFlowGraph.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ module ControlFlow {
165165
self.getRhs() = rhs.asInstruction()
166166
)
167167
}
168+
169+
/**
170+
* Holds if this node sets any field or element of `base` to `rhs`.
171+
*/
172+
predicate writesComponent(DataFlow::Node base, DataFlow::Node rhs) {
173+
writesElement(base, _, rhs) or writesField(base, _, rhs)
174+
}
168175
}
169176

170177
/**

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,6 @@ module Protobuf {
139139
}
140140
}
141141

142-
/**
143-
* Gets a field of a Message type.
144-
*/
145-
private Field getAMessageField() {
146-
result = any(MessageType msg).getField(_)
147-
or
148-
exists(Type base | base.getPointerType() instanceof MessageType | result = base.getField(_))
149-
}
150-
151142
/**
152143
* Gets the data-flow node representing the bottom of a stack of zero or more `ComponentReadNode`s.
153144
*
@@ -163,13 +154,9 @@ module Protobuf {
163154
*/
164155
private class WriteMessageFieldStep extends TaintTracking::AdditionalTaintStep {
165156
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
157+
[succ.getType(), succ.getType().getPointerType()] instanceof MessageType and
166158
exists(DataFlow::ReadNode base | succ = getUnderlyingNode(base) |
167-
any(DataFlow::Write w).writesField(base, getAMessageField(), pred)
168-
)
169-
or
170-
exists(DataFlow::ReadNode base | succ = getUnderlyingNode(base) |
171-
any(DataFlow::Write w).writesElement(base, _, pred) and
172-
[succ.getType(), succ.getType().getPointerType()] instanceof MessageType
159+
any(DataFlow::Write w).writesComponent(base, pred)
173160
)
174161
}
175162
}

0 commit comments

Comments
 (0)