1212 * external/cert/obligation/rule
1313 */
1414
15- import cpp
16- import codingstandards.c.cert
17- import codingstandards.c.OutOfBounds
18-
19- from
20- OOB:: BufferAccess ba , Expr bufferArg , Expr sizeArg , OOB:: PointerToObjectSource bufferSource ,
21- string message
22- where
23- not isExcluded ( ba , OutOfBoundsPackage:: doNotFormOutOfBoundsPointersOrArraySubscriptsQuery ( ) ) and
24- // exclude loops
25- not exists ( Loop loop | loop .getStmt ( ) .getChildStmt * ( ) = ba .getEnclosingStmt ( ) ) and
26- // exclude size arguments that are of type ssize_t
27- not sizeArg .getAChild * ( ) .( VariableAccess ) .getTarget ( ) .getType ( ) instanceof Ssize_t and
28- // exclude size arguments that are assigned the result of a function call e.g. ftell
29- not sizeArg .getAChild * ( ) .( VariableAccess ) .getTarget ( ) .getAnAssignedValue ( ) instanceof FunctionCall and
30- // exclude field or array accesses for the size arguments
31- not sizeArg .getAChild * ( ) instanceof FieldAccess and
32- not sizeArg .getAChild * ( ) instanceof ArrayExpr and
33- (
34- exists ( int sizeArgValue , int bufferArgSize |
35- OOB:: isSizeArgGreaterThanBufferSize ( bufferArg , sizeArg , bufferSource , bufferArgSize , sizeArgValue , ba ) and
36- message =
37- "Buffer accesses offset " + sizeArgValue +
38- " which is greater than the fixed size " + bufferArgSize + " of the $@."
39- )
40- or
41- exists ( int sizeArgUpperBound , int sizeMult , int bufferArgSize |
42- OOB:: isSizeArgNotCheckedLessThanFixedBufferSize ( bufferArg , sizeArg , bufferSource ,
43- bufferArgSize , ba , sizeArgUpperBound , sizeMult ) and
44- message =
45- "Buffer may access up to offset " + sizeArgUpperBound + "*" + sizeMult +
46- " which is greater than the fixed size " + bufferArgSize + " of the $@."
47- )
48- or
49- OOB:: isSizeArgNotCheckedGreaterThanZero ( bufferArg , sizeArg , bufferSource , ba ) and
50- message = "Buffer access may be to a negative index in the buffer."
51- )
52- select ba , message , bufferSource , "buffer"
15+ import cpp
16+ import codingstandards.c.cert
17+ import codingstandards.c.OutOfBounds
18+
19+ from
20+ OOB:: BufferAccess ba , Expr bufferArg , Expr sizeArg , OOB:: PointerToObjectSource bufferSource ,
21+ string message
22+ where
23+ not isExcluded ( ba , OutOfBoundsPackage:: doNotFormOutOfBoundsPointersOrArraySubscriptsQuery ( ) ) and
24+ // exclude loops
25+ not exists ( Loop loop | loop .getStmt ( ) .getChildStmt * ( ) = ba .getEnclosingStmt ( ) ) and
26+ // exclude size arguments that are of type ssize_t
27+ not sizeArg .getAChild * ( ) .( VariableAccess ) .getTarget ( ) .getType ( ) instanceof Ssize_t and
28+ // exclude size arguments that are assigned the result of a function call e.g. ftell
29+ not sizeArg .getAChild * ( ) .( VariableAccess ) .getTarget ( ) .getAnAssignedValue ( ) instanceof FunctionCall and
30+ // exclude field or array accesses for the size arguments
31+ not sizeArg .getAChild * ( ) instanceof FieldAccess and
32+ not sizeArg .getAChild * ( ) instanceof ArrayExpr and
33+ (
34+ exists ( int sizeArgValue , int bufferArgSize |
35+ OOB:: isSizeArgGreaterThanBufferSize ( bufferArg , sizeArg , bufferSource , bufferArgSize ,
36+ sizeArgValue , ba ) and
37+ message =
38+ "Buffer accesses offset " + sizeArgValue + " which is greater than the fixed size " +
39+ bufferArgSize + " of the $@."
40+ )
41+ or
42+ exists ( int sizeArgUpperBound , int sizeMult , int bufferArgSize |
43+ OOB:: isSizeArgNotCheckedLessThanFixedBufferSize ( bufferArg , sizeArg , bufferSource ,
44+ bufferArgSize , ba , sizeArgUpperBound , sizeMult ) and
45+ message =
46+ "Buffer may access up to offset " + sizeArgUpperBound + "*" + sizeMult +
47+ " which is greater than the fixed size " + bufferArgSize + " of the $@."
48+ )
49+ or
50+ OOB:: isSizeArgNotCheckedGreaterThanZero ( bufferArg , sizeArg , bufferSource , ba ) and
51+ message = "Buffer access may be to a negative index in the buffer."
52+ )
53+ select ba , message , bufferSource , "buffer"
0 commit comments