Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43a231f

Browse files
committed
C++: Store steps now go from operands to instructions, and read steps now go from instructions and operands. There are a couple of read steps that still target instructions because I couldn't decide on an operand to target.
1 parent 02ca8fe commit 43a231f

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private class ArrayContent extends Content, TArrayContent {
228228
private predicate fieldStoreStepNoChi(Node node1, FieldContent f, PostUpdateNode node2) {
229229
exists(StoreInstruction store, Class c |
230230
store = node2.asInstruction() and
231-
store.getSourceValue() = node1.asInstruction() and
231+
store.getSourceValueOperand() = node1.asOperand() and
232232
getWrittenField(store, f.(FieldContent).getAField(), c) and
233233
f.hasOffset(c, _, _)
234234
)
@@ -251,27 +251,28 @@ private predicate getWrittenField(Instruction instr, Field f, Class c) {
251251
}
252252

253253
private predicate fieldStoreStepChi(Node node1, FieldContent f, PostUpdateNode node2) {
254-
exists(StoreInstruction store, ChiInstruction chi |
255-
node1.asInstruction() = store and
254+
exists(StoreValueOperand operand, ChiInstruction chi |
255+
node1.asOperand() = operand and
256256
node2.asInstruction() = chi and
257-
chi.getPartial() = store and
257+
chi.getPartial() = operand.getUse() and
258258
exists(Class c |
259259
c = chi.getResultType() and
260260
exists(int startBit, int endBit |
261261
chi.getUpdatedInterval(startBit, endBit) and
262262
f.hasOffset(c, startBit, endBit)
263263
)
264264
or
265-
getWrittenField(store, f.getAField(), c) and
265+
getWrittenField(operand.getUse(), f.getAField(), c) and
266266
f.hasOffset(c, _, _)
267267
)
268268
)
269269
}
270270

271271
private predicate arrayStoreStepChi(Node node1, ArrayContent a, PostUpdateNode node2) {
272272
a = TArrayContent() and
273-
exists(StoreInstruction store |
274-
node1.asInstruction() = store and
273+
exists(StoreValueOperand operand, StoreInstruction store |
274+
store.getSourceValueOperand() = operand and
275+
node1.asOperand() = operand and
275276
(
276277
// `x[i] = taint()`
277278
// This matches the characteristic predicate in `ArrayStoreNode`.
@@ -304,7 +305,7 @@ predicate storeStep(Node node1, Content f, PostUpdateNode node2) {
304305
private predicate fieldStoreStepAfterArraySuppression(
305306
Node node1, FieldContent f, PostUpdateNode node2
306307
) {
307-
exists(BufferMayWriteSideEffectInstruction write, ChiInstruction chi, Class c |
308+
exists(WriteSideEffectInstruction write, ChiInstruction chi, Class c |
308309
not chi.isResultConflated() and
309310
node1.asInstruction() = chi and
310311
node2.asInstruction() = chi and
@@ -332,17 +333,17 @@ private predicate getLoadedField(LoadInstruction load, Field f, Class c) {
332333
* `node2`.
333334
*/
334335
private predicate fieldReadStep(Node node1, FieldContent f, Node node2) {
335-
exists(LoadInstruction load |
336-
node2.asInstruction() = load and
337-
node1.asInstruction() = load.getSourceValueOperand().getAnyDef() and
336+
exists(LoadOperand operand |
337+
node2.asOperand() = operand and
338+
node1.asInstruction() = operand.getAnyDef() and
338339
exists(Class c |
339-
c = load.getSourceValueOperand().getAnyDef().getResultType() and
340+
c = operand.getAnyDef().getResultType() and
340341
exists(int startBit, int endBit |
341-
load.getSourceValueOperand().getUsedInterval(unbindInt(startBit), unbindInt(endBit)) and
342+
operand.getUsedInterval(unbindInt(startBit), unbindInt(endBit)) and
342343
f.hasOffset(c, startBit, endBit)
343344
)
344345
or
345-
getLoadedField(load, f.getAField(), c) and
346+
getLoadedField(operand.getUse(), f.getAField(), c) and
346347
f.hasOffset(c, _, _)
347348
)
348349
)
@@ -363,7 +364,7 @@ private predicate fieldReadStep(Node node1, FieldContent f, Node node2) {
363364
*/
364365
predicate suppressArrayRead(Node node1, ArrayContent a, Node node2) {
365366
a = TArrayContent() and
366-
exists(BufferMayWriteSideEffectInstruction write, ChiInstruction chi |
367+
exists(WriteSideEffectInstruction write, ChiInstruction chi |
367368
node1.asInstruction() = write and
368369
node2.asInstruction() = chi and
369370
chi.getPartial() = write and
@@ -393,11 +394,11 @@ private Instruction skipCopyValueInstructions(Instruction instr) {
393394
private predicate arrayReadStep(Node node1, ArrayContent a, Node node2) {
394395
a = TArrayContent() and
395396
// Explicit dereferences such as `*p` or `p[i]` where `p` is a pointer or array.
396-
exists(LoadInstruction load, Instruction address |
397-
load.getSourceValueOperand().isDefinitionInexact() and
398-
node1.asInstruction() = load.getSourceValueOperand().getAnyDef() and
399-
load = node2.asInstruction() and
400-
address = skipCopyValueInstructions(load.getSourceAddress()) and
397+
exists(LoadOperand operand, Instruction address |
398+
operand.isDefinitionInexact() and
399+
node1.asInstruction() = operand.getAnyDef() and
400+
operand = node2.asOperand() and
401+
address = skipCopyValueInstructions(operand.getUse().(LoadInstruction).getSourceAddress()) and
401402
(
402403
address instanceof LoadInstruction or
403404
address instanceof ArrayToPointerConvertInstruction or
@@ -423,13 +424,13 @@ private predicate arrayReadStep(Node node1, ArrayContent a, Node node2) {
423424
*/
424425
private predicate exactReadStep(Node node1, ArrayContent a, Node node2) {
425426
a = TArrayContent() and
426-
exists(BufferMayWriteSideEffectInstruction write, ChiInstruction chi |
427+
exists(WriteSideEffectInstruction write, ChiInstruction chi |
427428
not chi.isResultConflated() and
428429
chi.getPartial() = write and
429430
node1.asInstruction() = write and
430431
node2.asInstruction() = chi and
431432
// To distinquish this case from the `arrayReadStep` case we require that the entire variable was
432-
// overwritten by the `BufferMayWriteSideEffectInstruction` (i.e., there is a load that reads the
433+
// overwritten by the `WriteSideEffectInstruction` (i.e., there is a load that reads the
433434
// entire variable).
434435
exists(LoadInstruction load | load.getSourceValue() = chi)
435436
)

0 commit comments

Comments
 (0)