Merge pull request #475 from geoffw0/av_164

CPP: Fix AV Rule 164
This commit is contained in:
Jonas Jensen
2018-11-19 14:23:36 +01:00
committed by GitHub
4 changed files with 38 additions and 1 deletions

View File

@@ -35,7 +35,7 @@ predicate constantValue(Expr e, int value) {
predicate violation(BinaryBitwiseOperation op, int lhsBytes, int value) {
(op instanceof LShiftExpr or op instanceof RShiftExpr) and
constantValue(op.getRightOperand(), value) and
lhsBytes = op.getLeftOperand().getType().getSize() and
lhsBytes = op.getLeftOperand().getExplicitlyConverted().getType().getSize() and
(value < 0 or value >= lhsBytes * 8)
}

View File

@@ -0,0 +1,8 @@
| test.c:3:2:3:9 | ... >> ... | AV Rule 164: The right-hand operand (here a value is -1) of this shift shall lie between 0 and 7. |
| test.c:6:2:6:8 | ... >> ... | AV Rule 164: The right-hand operand (here a value is 8) of this shift shall lie between 0 and 7. |
| test.c:8:2:8:9 | ... << ... | AV Rule 164: The right-hand operand (here a value is -1) of this shift shall lie between 0 and 7. |
| test.c:11:2:11:8 | ... << ... | AV Rule 164: The right-hand operand (here a value is 8) of this shift shall lie between 0 and 7. |
| test.c:18:2:18:9 | ... >> ... | AV Rule 164: The right-hand operand (here a value is -1) of this shift shall lie between 0 and 7. |
| test.c:21:2:21:8 | ... >> ... | AV Rule 164: The right-hand operand (here a value is 8) of this shift shall lie between 0 and 7. |
| test.c:23:2:23:25 | ... >> ... | AV Rule 164: The right-hand operand (here a value is -1) of this shift shall lie between 0 and 7. |
| test.c:26:2:26:24 | ... >> ... | AV Rule 164: The right-hand operand (here a value is 8) of this shift shall lie between 0 and 7. |

View File

@@ -0,0 +1 @@
jsf/4.21 Operators/AV Rule 164.ql

View File

@@ -0,0 +1,28 @@
void f(unsigned char uc, signed char sc, int i) {
uc >> -1; // BAD
uc >> 0;
uc >> 7;
uc >> 8; // BAD
uc << -1; // BAD
uc << 0;
uc << 7;
uc << 8; // BAD
uc >>= -1; // BAD [NOT DETECTED]
uc >>= 0; // BAD [NOT DETECTED]
uc >>= 7;
uc >>= 8; // BAD [NOT DETECTED]
sc >> -1; // BAD
sc >> 0;
sc >> 7;
sc >> 8; // BAD
((unsigned char)i) >> -1; // BAD
((unsigned char)i) >> 0;
((unsigned char)i) >> 7;
((unsigned char)i) >> 8; // BAD
}