Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
We are mostly losing precision due to excluding float operations from range analysis.
  • Loading branch information
d10c committed Jul 1, 2024
1 parent ab15d79 commit fd21a72
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cpp/ql/src/Security/CWE/CWE-190/ArithmeticUncontrolled.ql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @kind path-problem
* @problem.severity warning
* @security-severity 8.6
* @precision high
* @precision medium
* @id cpp/uncontrolled-arithmetic
* @tags security
* external/cwe/cwe-190
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int overeager_wraparound(unsigned int u32bound, unsigned long long u64bound) {

int negative_zero(double dbl) {
if (dbl >= 0) {
return dbl >= -dbl; // GOOD [FALSE POSITIVE]
return dbl >= -dbl; // GOOD
}
return 0;
}
Expand Down Expand Up @@ -334,7 +334,7 @@ int nan2(double x) {
if (x < 0.0) {
return 100;
}
else if (x >= 0.0) { // BAD [Always true]
else if (x >= 0.0) { // BAD [Always true] [NOT DETECTED]
return 200;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
| PointlessComparison.c:126:12:126:18 | ... >= ... | Comparison is always true because a >= 20. |
| PointlessComparison.c:129:12:129:16 | ... > ... | Comparison is always false because a <= 3. |
| PointlessComparison.c:197:7:197:11 | ... < ... | Comparison is always false because x >= 0. |
| PointlessComparison.c:264:12:264:22 | ... >= ... | Comparison is always true because dbl >= 0 and 0 >= - .... |
| PointlessComparison.c:273:9:273:18 | ... > ... | Comparison is always false because c <= 0. |
| PointlessComparison.c:283:13:283:19 | ... >= ... | Comparison is always true because c >= 11. |
| PointlessComparison.c:294:9:294:16 | ... >= ... | Comparison is always false because ui1 <= 0. |
| PointlessComparison.c:303:9:303:14 | ... >= ... | Comparison is always false because c <= 0. |
| PointlessComparison.c:312:9:312:14 | ... >= ... | Comparison is always false because c <= 0. |
| PointlessComparison.c:337:14:337:21 | ... >= ... | Comparison is always true because x >= 0. |
| PointlessComparison.c:372:6:372:16 | ... >= ... | Comparison is always true because ... >> ... >= 1. |
| PointlessComparison.c:373:6:373:16 | ... >= ... | Comparison is always false because ... >> ... <= 1. |
| PointlessComparison.c:383:6:383:17 | ... >= ... | Comparison is always false because ... & ... <= 2. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ edges
| test.c:81:13:81:29 | ... ^ ... | test.c:83:9:83:9 | r | provenance | |
| test.c:81:14:81:17 | call to rand | test.c:81:13:81:29 | ... ^ ... | provenance | |
| test.c:81:23:81:26 | call to rand | test.c:81:13:81:29 | ... ^ ... | provenance | |
| test.c:104:13:104:16 | call to rand | test.c:104:13:104:16 | call to rand | provenance | |
| test.c:104:13:104:16 | call to rand | test.c:105:5:105:42 | ... = ... | provenance | |
| test.c:105:5:105:42 | ... = ... | test.c:106:13:106:13 | r | provenance | |
| test.c:106:13:106:13 | r | test.c:110:18:110:18 | r | provenance | |
| test.c:110:18:110:18 | r | test.c:111:3:111:3 | r | provenance | |
| test.c:125:13:125:16 | call to rand | test.c:125:13:125:16 | call to rand | provenance | |
| test.c:125:13:125:16 | call to rand | test.c:127:9:127:9 | r | provenance | |
| test.c:131:13:131:16 | call to rand | test.c:131:13:131:16 | call to rand | provenance | |
Expand Down Expand Up @@ -77,6 +82,12 @@ nodes
| test.c:81:14:81:17 | call to rand | semmle.label | call to rand |
| test.c:81:23:81:26 | call to rand | semmle.label | call to rand |
| test.c:83:9:83:9 | r | semmle.label | r |
| test.c:104:13:104:16 | call to rand | semmle.label | call to rand |
| test.c:104:13:104:16 | call to rand | semmle.label | call to rand |
| test.c:105:5:105:42 | ... = ... | semmle.label | ... = ... |
| test.c:106:13:106:13 | r | semmle.label | r |
| test.c:110:18:110:18 | r | semmle.label | r |
| test.c:111:3:111:3 | r | semmle.label | r |
| test.c:125:13:125:16 | call to rand | semmle.label | call to rand |
| test.c:125:13:125:16 | call to rand | semmle.label | call to rand |
| test.c:127:9:127:9 | r | semmle.label | r |
Expand Down Expand Up @@ -149,6 +160,7 @@ subpaths
| test.c:77:9:77:9 | r | test.c:75:13:75:19 | call to rand | test.c:77:9:77:9 | r | This arithmetic expression depends on an $@, potentially causing an overflow. | test.c:75:13:75:19 | call to rand | uncontrolled value |
| test.c:83:9:83:9 | r | test.c:81:14:81:17 | call to rand | test.c:83:9:83:9 | r | This arithmetic expression depends on an $@, potentially causing an overflow. | test.c:81:14:81:17 | call to rand | uncontrolled value |
| test.c:83:9:83:9 | r | test.c:81:23:81:26 | call to rand | test.c:83:9:83:9 | r | This arithmetic expression depends on an $@, potentially causing an overflow. | test.c:81:23:81:26 | call to rand | uncontrolled value |
| test.c:111:3:111:3 | r | test.c:104:13:104:16 | call to rand | test.c:111:3:111:3 | r | This arithmetic expression depends on an $@, potentially causing an overflow. | test.c:104:13:104:16 | call to rand | uncontrolled value |
| test.c:127:9:127:9 | r | test.c:125:13:125:16 | call to rand | test.c:127:9:127:9 | r | This arithmetic expression depends on an $@, potentially causing an overflow. | test.c:125:13:125:16 | call to rand | uncontrolled value |
| test.c:133:5:133:5 | r | test.c:131:13:131:16 | call to rand | test.c:133:5:133:5 | r | This arithmetic expression depends on an $@, potentially causing an overflow. | test.c:131:13:131:16 | call to rand | uncontrolled value |
| test.c:139:10:139:10 | r | test.c:137:13:137:16 | call to rand | test.c:139:10:139:10 | r | This arithmetic expression depends on an $@, potentially causing an overflow. | test.c:137:13:137:16 | call to rand | uncontrolled value |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void randomTester() {
}

void add_100(int r) {
r += 100; // GOOD
r += 100; // GOOD [FALSE POSITIVE]
}

void randomTester2(int bound, int min, int max) {
Expand Down

0 comments on commit fd21a72

Please sign in to comment.