@@ -1129,6 +1129,37 @@ module OOB {
1129
1129
)
1130
1130
}
1131
1131
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
+
1132
1163
/**
1133
1164
* Holds if the BufferAccess is accessed with a `base + accessOffset` on a buffer that was
1134
1165
* allocated a size of the form `base + allocationOffset`.
@@ -1150,9 +1181,12 @@ module OOB {
1150
1181
sourceSizeExpr = source .getSizeExprSource ( sourceSizeExprBase , sourceSizeExprOffset ) and
1151
1182
bufferUseNonComputableSize ( bufferArg , source ) and
1152
1183
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
+ )
1156
1190
)
1157
1191
}
1158
1192
0 commit comments