@@ -282,24 +282,16 @@ class FatPointer extends TFatPointer {
282282}
283283
284284predicate srcSinkLengthMap (
285- DataFlow:: Node src , DataFlow:: Node sink , // both `src` and `sink` are fat pointers
286- int srcOffset , int sinkOffset , int length
285+ FatPointer start , FatPointer end , int srcOffset , int sinkOffset , int length
287286) {
288- TrackArray:: flow ( src , sink ) and
289- exists ( FatPointer start , FatPointer end |
290- /* Reiterate the data flow configuration here. */
291- src = start .getNode ( ) and
292- sink .asExpr ( ) = end .getBasePointer ( )
293- |
294- srcOffset = start .getOffset ( ) and
295- sinkOffset = end .getOffset ( ) and
296- (
297- /* Base case: The object is allocated and a fat pointer created. */
298- length = start .getLength ( )
299- or
300- /* Recursive case: A fat pointer is derived from a fat pointer. */
301- srcSinkLengthMap ( _, _, _, _, length )
302- )
287+ srcOffset = start .getOffset ( ) and
288+ sinkOffset = end .getOffset ( ) and
289+ (
290+ /* Base case: The object is allocated and a fat pointer created. */
291+ length = start .getLength ( )
292+ or
293+ /* Recursive case: A fat pointer is derived from a fat pointer. */
294+ srcSinkLengthMap ( _, start , _, srcOffset , length )
303295 )
304296}
305297
@@ -321,13 +313,20 @@ module TrackArray = DataFlow::Global<TrackArrayConfig>;
321313
322314import TrackArray:: PathGraph
323315
324- from TrackArray:: PathNode source , TrackArray:: PathNode sink , string message
316+ from TrackArray:: PathNode src , TrackArray:: PathNode sink , string message
325317where
326318 not isExcluded ( sink .getNode ( ) .asExpr ( ) ,
327319 Memory1Package:: pointerArithmeticFormsAnInvalidPointerQuery ( ) ) and
328- none ( ) and // TODO
329- message =
330- // "This pointer has offset " + pointerOffset +
331- // " when the minimum possible length of the object might be " + arrayLength + "."
332- "TODO"
333- select sink , source , sink , message
320+ exists ( FatPointer start , FatPointer end , int srcOffset , int sinkOffset , int length |
321+ TrackArray:: flowPath ( src , sink ) and
322+ /* Reiterate the data flow configuration here. */
323+ src .getNode ( ) = start .getNode ( ) and
324+ sink .getNode ( ) .asExpr ( ) = end .getBasePointer ( ) and
325+ srcSinkLengthMap ( start , end , srcOffset , sinkOffset , length ) and
326+ (
327+ srcOffset + sinkOffset < 0 or // Underflow detection
328+ srcOffset + sinkOffset > length // Overflow detection
329+ ) and
330+ message = "srcOffset: " + srcOffset + ", sinkOffset: " + sinkOffset + ", length: " + length
331+ )
332+ select sink , src , sink , message
0 commit comments