@@ -4,7 +4,7 @@ import semmle.code.cpp.controlflow.Dominance
44/* Guarding */
55
66/** is the size of this use guarded using 'abs'? */
7- predicate guardedAbs ( BinaryArithmeticOperation e , Expr use ) {
7+ predicate guardedAbs ( Operation e , Expr use ) {
88 exists ( FunctionCall fc |
99 fc .getTarget ( ) .getName ( ) = "abs" |
1010 fc .getArgument ( 0 ) .getAChild * ( ) = use
@@ -13,7 +13,7 @@ predicate guardedAbs(BinaryArithmeticOperation e, Expr use) {
1313}
1414
1515/** is the size of this use guarded to be less than something? */
16- predicate guardedLesser ( BinaryArithmeticOperation e , Expr use ) {
16+ predicate guardedLesser ( Operation e , Expr use ) {
1717 exists ( IfStmt c , RelationalOperation guard |
1818 use = guard .getLesserOperand ( ) .getAChild * ( ) and
1919 guard = c .getControllingExpr ( ) .getAChild * ( ) and
@@ -33,7 +33,7 @@ predicate guardedLesser(BinaryArithmeticOperation e, Expr use) {
3333}
3434
3535/** is the size of this use guarded to be greater than something? */
36- predicate guardedGreater ( BinaryArithmeticOperation e , Expr use ) {
36+ predicate guardedGreater ( Operation e , Expr use ) {
3737 exists ( IfStmt c , RelationalOperation guard |
3838 use = guard .getGreaterOperand ( ) .getAChild * ( ) and
3939 guard = c .getControllingExpr ( ) .getAChild * ( ) and
@@ -58,24 +58,26 @@ VariableAccess varUse(LocalScopeVariable v) {
5858}
5959
6060/** is e not guarded against overflow by use? */
61- predicate missingGuardAgainstOverflow ( BinaryArithmeticOperation e , VariableAccess use ) {
61+ predicate missingGuardAgainstOverflow ( Operation e , VariableAccess use ) {
6262 use = e .getAnOperand ( ) and
6363 exists ( LocalScopeVariable v | use .getTarget ( ) = v |
6464 // overflow possible if large
6565 ( e instanceof AddExpr and not guardedLesser ( e , varUse ( v ) ) ) or
66+ ( e instanceof IncrementOperation and not guardedLesser ( e , varUse ( v ) ) ) or
6667 // overflow possible if large or small
6768 ( e instanceof MulExpr and
6869 not ( guardedLesser ( e , varUse ( v ) ) and guardedGreater ( e , varUse ( v ) ) ) )
6970 )
7071}
7172
7273/** is e not guarded against underflow by use? */
73- predicate missingGuardAgainstUnderflow ( BinaryArithmeticOperation e , VariableAccess use ) {
74+ predicate missingGuardAgainstUnderflow ( Operation e , VariableAccess use ) {
7475 use = e .getAnOperand ( ) and
7576 exists ( LocalScopeVariable v | use .getTarget ( ) = v |
7677 // underflow possible if use is left operand and small
77- ( e instanceof SubExpr and
78- ( use = e .getLeftOperand ( ) and not guardedGreater ( e , varUse ( v ) ) ) ) or
78+ ( use = e .( SubExpr ) .getLeftOperand ( ) and not guardedGreater ( e , varUse ( v ) ) ) or
79+ // underflow possible if small
80+ ( e instanceof DecrementOperation and not guardedGreater ( e , varUse ( v ) ) ) or
7981 // underflow possible if large or small
8082 ( e instanceof MulExpr and
8183 not ( guardedLesser ( e , varUse ( v ) ) and guardedGreater ( e , varUse ( v ) ) ) )
0 commit comments