File tree Expand file tree Collapse file tree
ql_demos/cpp/ChakraCore-bad-overflow-check/steps Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import cpp
2+
3+ /** Matches `var < var + ???`. */
4+ predicate overflowCheck ( LocalScopeVariable var , AddExpr add ) {
5+ exists ( RelationalOperation compare |
6+ compare .getAnOperand ( ) = var .getAnAccess ( ) and
7+ compare .getAnOperand ( ) = add and
8+ add .getAnOperand ( ) = var .getAnAccess ( )
9+ )
10+ }
11+
12+ from LocalScopeVariable var , AddExpr add
13+ where overflowCheck ( var , add )
14+ select add , "Overflow check on variable of type " + var .getUnderlyingType ( )
Original file line number Diff line number Diff line change 1+ import cpp
2+
3+ /** Matches `var < var + ???`. */
4+ predicate overflowCheck ( LocalScopeVariable var , AddExpr add ) {
5+ exists ( RelationalOperation compare |
6+ compare .getAnOperand ( ) = var .getAnAccess ( ) and
7+ compare .getAnOperand ( ) = add and
8+ add .getAnOperand ( ) = var .getAnAccess ( )
9+ )
10+ }
11+
12+ from LocalScopeVariable var , AddExpr add
13+ where overflowCheck ( var , add )
14+ and var .getType ( ) .getSize ( ) < 4
15+ select add , "Overflow check on variable of type " + var .getUnderlyingType ( )
Original file line number Diff line number Diff line change 1+ import cpp
2+
3+ /** Matches `var < var + ???`. */
4+ predicate overflowCheck ( LocalScopeVariable var , AddExpr add ) {
5+ exists ( RelationalOperation compare |
6+ compare .getAnOperand ( ) = var .getAnAccess ( ) and
7+ compare .getAnOperand ( ) = add and
8+ add .getAnOperand ( ) = var .getAnAccess ( )
9+ )
10+ }
11+
12+ from LocalScopeVariable var , AddExpr add
13+ where overflowCheck ( var , add )
14+ and var .getType ( ) .getSize ( ) < 4
15+ and not add .getConversion + ( ) .getType ( ) .getSize ( ) < 4
16+ select add , "Bad overflow check on variable of type " + var .getUnderlyingType ( )
You can’t perform that action at this time.
0 commit comments