@@ -1129,6 +1129,37 @@ module OOB {
11291129 )
11301130 }
11311131
1132+ /**
1133+ * Holds if `a` and `b` are function calls to the same target function and
1134+ * have identical arguments (determined by their global value number or `VariableAccess` targets).
1135+ */
1136+ bindingset [ a, b]
1137+ private predicate areFunctionCallsSyntacticallySame ( FunctionCall a , FunctionCall b ) {
1138+ a .getTarget ( ) = b .getTarget ( ) and
1139+ (
1140+ exists ( a .getAnArgument ( ) )
1141+ implies
1142+ not exists ( int i , Expr argA , Expr argB |
1143+ i = [ 0 .. a .getTarget ( ) .getNumberOfParameters ( ) - 1 ]
1144+ |
1145+ argA = a .getArgument ( i ) and
1146+ argB = b .getArgument ( i ) and
1147+ not globalValueNumber ( argA ) = globalValueNumber ( argB ) and
1148+ not argA .( VariableAccess ) .getTarget ( ) = argB .( VariableAccess ) .getTarget ( )
1149+ )
1150+ )
1151+ }
1152+
1153+ /**
1154+ * Holds if `a` and `b` have the same global value number or are syntactically identical function calls
1155+ */
1156+ bindingset [ a, b]
1157+ private predicate isGVNOrFunctionCallSame ( Expr a , Expr b ) {
1158+ globalValueNumber ( a ) = globalValueNumber ( b )
1159+ or
1160+ areFunctionCallsSyntacticallySame ( a , b )
1161+ }
1162+
11321163 /**
11331164 * Holds if the BufferAccess is accessed with a `base + accessOffset` on a buffer that was
11341165 * allocated a size of the form `base + allocationOffset`.
@@ -1150,9 +1181,12 @@ module OOB {
11501181 sourceSizeExpr = source .getSizeExprSource ( sourceSizeExprBase , sourceSizeExprOffset ) and
11511182 bufferUseNonComputableSize ( bufferArg , source ) and
11521183 not globalValueNumber ( sourceSizeExpr ) = globalValueNumber ( bufferSizeArg ) and
1153- sizeArgOffset = getArithmeticOffsetValue ( bufferSizeArg .getAChild * ( ) , _) and
1154- bufferArgOffset = getArithmeticOffsetValue ( bufferArg , _) and
1155- sourceSizeExprOffset + bufferArgOffset < sizeArgOffset
1184+ exists ( Expr sizeArgBase |
1185+ sizeArgOffset = getArithmeticOffsetValue ( bufferSizeArg .getAChild * ( ) , sizeArgBase ) and
1186+ isGVNOrFunctionCallSame ( sizeArgBase , sourceSizeExprBase ) and
1187+ bufferArgOffset = getArithmeticOffsetValue ( bufferArg , _) and
1188+ sourceSizeExprOffset + bufferArgOffset < sizeArgOffset
1189+ )
11561190 )
11571191 }
11581192
0 commit comments