Skip to content

Commit 2ce2c0a

Browse files
authored
Merge pull request #475 from geoffw0/av_164
CPP: Fix AV Rule 164
2 parents dd4c965 + d1adc0e commit 2ce2c0a

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

cpp/ql/src/jsf/4.21 Operators/AV Rule 164.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ predicate constantValue(Expr e, int value) {
3535
predicate violation(BinaryBitwiseOperation op, int lhsBytes, int value) {
3636
(op instanceof LShiftExpr or op instanceof RShiftExpr) and
3737
constantValue(op.getRightOperand(), value) and
38-
lhsBytes = op.getLeftOperand().getType().getSize() and
38+
lhsBytes = op.getLeftOperand().getExplicitlyConverted().getType().getSize() and
3939
(value < 0 or value >= lhsBytes * 8)
4040
}
4141

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| 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. |
2+
| 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. |
3+
| 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. |
4+
| 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. |
5+
| 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. |
6+
| 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. |
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. |
8+
| 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. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jsf/4.21 Operators/AV Rule 164.ql
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
void f(unsigned char uc, signed char sc, int i) {
3+
uc >> -1; // BAD
4+
uc >> 0;
5+
uc >> 7;
6+
uc >> 8; // BAD
7+
8+
uc << -1; // BAD
9+
uc << 0;
10+
uc << 7;
11+
uc << 8; // BAD
12+
13+
uc >>= -1; // BAD [NOT DETECTED]
14+
uc >>= 0; // BAD [NOT DETECTED]
15+
uc >>= 7;
16+
uc >>= 8; // BAD [NOT DETECTED]
17+
18+
sc >> -1; // BAD
19+
sc >> 0;
20+
sc >> 7;
21+
sc >> 8; // BAD
22+
23+
((unsigned char)i) >> -1; // BAD
24+
((unsigned char)i) >> 0;
25+
((unsigned char)i) >> 7;
26+
((unsigned char)i) >> 8; // BAD
27+
}
28+

0 commit comments

Comments
 (0)