1414
1515import cpp
1616import codingstandards.cpp.misra
17+ import semmle.code.cpp.ir.IR
1718import semmle.code.cpp.dataflow.new.DataFlow
1819import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
1920import semmle.code.cpp.security.BufferAccess
@@ -216,7 +217,9 @@ class PointerFormation extends TPointerFormation {
216217 /**
217218 * Gets the data-flow node associated with this pointer formation.
218219 */
219- DataFlow:: Node getNode ( ) { result .asExpr ( ) = this .asExpr ( ) }
220+ DataFlow:: Node getNode ( ) {
221+ result .asInstruction ( ) .( PointerAddInstruction ) .getAst ( ) = this .asExpr ( )
222+ }
220223
221224 Location getLocation ( ) {
222225 result = this .asArrayExpr ( ) .getLocation ( ) or
@@ -279,6 +282,16 @@ class FatPointer extends TFatPointer {
279282 result = this .asAllocated ( ) .asExpr ( ) or
280283 result = this .asIndexAdjusted ( ) .getBase ( )
281284 }
285+
286+ DataFlow:: Node getBasePointerNode ( ) {
287+ exists ( PointerAddInstruction ptrAdd |
288+ result .asInstruction ( ) = ptrAdd .getAnOperand ( ) .getDef ( ) and
289+ (
290+ result .asInstruction ( ) .getAst ( ) = this .asIndexAdjusted ( ) .getBase ( ) or
291+ result .asInstruction ( ) .getAst ( ) = this .asAllocated ( ) .asExpr ( )
292+ )
293+ )
294+ }
282295}
283296
284297predicate srcSinkLengthMap (
@@ -288,7 +301,7 @@ predicate srcSinkLengthMap(
288301 TrackArray:: flowPath ( src , sink ) and
289302 /* Reiterate the data flow configuration here. */
290303 src .getNode ( ) = start .getNode ( ) and
291- sink .getNode ( ) . asExpr ( ) = end .getBasePointer ( )
304+ sink .getNode ( ) = end .getBasePointerNode ( )
292305 |
293306 srcOffset = start .getOffset ( ) and
294307 sinkOffset = end .getOffset ( ) and
@@ -312,7 +325,7 @@ module TrackArrayConfig implements DataFlow::ConfigSig {
312325 }
313326
314327 predicate isSink ( DataFlow:: Node node ) {
315- exists ( FatPointer fatPointer | node . asExpr ( ) = fatPointer .getBasePointer ( ) )
328+ exists ( FatPointer fatPointer | node = fatPointer .getBasePointerNode ( ) )
316329 }
317330}
318331
0 commit comments