Skip to content

Commit a40c1d5

Browse files
committed
C++: Add FP tests.
1 parent 4ca6c80 commit a40c1d5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cpp/ql/test/query-tests/Critical/MissingCheckScanf/MissingCheckScanf.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ edges
5252
| test.cpp:541:39:541:40 | sscanf output argument | test.cpp:549:8:549:8 | e | provenance | |
5353
| test.cpp:541:43:541:44 | sscanf output argument | test.cpp:545:8:545:8 | f | provenance | |
5454
| test.cpp:541:43:541:44 | sscanf output argument | test.cpp:550:8:550:8 | f | provenance | |
55+
| test.cpp:559:30:559:31 | scanf output argument | test.cpp:561:9:561:9 | i | provenance | |
56+
| test.cpp:567:35:567:36 | scanf output argument | test.cpp:569:9:569:9 | i | provenance | |
57+
| test.cpp:575:30:575:31 | scanf output argument | test.cpp:577:9:577:9 | i | provenance | |
5558
nodes
5659
| test.cpp:34:15:34:16 | scanf output argument | semmle.label | scanf output argument |
5760
| test.cpp:35:7:35:7 | i | semmle.label | i |
@@ -154,6 +157,12 @@ nodes
154157
| test.cpp:548:8:548:8 | d | semmle.label | d |
155158
| test.cpp:549:8:549:8 | e | semmle.label | e |
156159
| test.cpp:550:8:550:8 | f | semmle.label | f |
160+
| test.cpp:559:30:559:31 | scanf output argument | semmle.label | scanf output argument |
161+
| test.cpp:561:9:561:9 | i | semmle.label | i |
162+
| test.cpp:567:35:567:36 | scanf output argument | semmle.label | scanf output argument |
163+
| test.cpp:569:9:569:9 | i | semmle.label | i |
164+
| test.cpp:575:30:575:31 | scanf output argument | semmle.label | scanf output argument |
165+
| test.cpp:577:9:577:9 | i | semmle.label | i |
157166
subpaths
158167
#select
159168
| test.cpp:35:7:35:7 | i | test.cpp:34:15:34:16 | scanf output argument | test.cpp:35:7:35:7 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:34:3:34:7 | call to scanf | call to scanf |
@@ -177,3 +186,6 @@ subpaths
177186
| test.cpp:484:9:484:9 | i | test.cpp:480:25:480:26 | scanf output argument | test.cpp:484:9:484:9 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:480:13:480:17 | call to scanf | call to scanf |
178187
| test.cpp:495:8:495:8 | i | test.cpp:491:25:491:26 | scanf output argument | test.cpp:495:8:495:8 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:491:13:491:17 | call to scanf | call to scanf |
179188
| test.cpp:545:8:545:8 | f | test.cpp:541:43:541:44 | sscanf output argument | test.cpp:545:8:545:8 | f | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 3. | test.cpp:541:10:541:15 | call to sscanf | call to sscanf |
189+
| test.cpp:561:9:561:9 | i | test.cpp:559:30:559:31 | scanf output argument | test.cpp:561:9:561:9 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:559:18:559:22 | call to scanf | call to scanf |
190+
| test.cpp:569:9:569:9 | i | test.cpp:567:35:567:36 | scanf output argument | test.cpp:569:9:569:9 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:567:23:567:27 | call to scanf | call to scanf |
191+
| test.cpp:577:9:577:9 | i | test.cpp:575:30:575:31 | scanf output argument | test.cpp:577:9:577:9 | i | This variable is read, but may not have been written. It should be guarded by a check that the $@ returns at least 1. | test.cpp:575:18:575:22 | call to scanf | call to scanf |

cpp/ql/test/query-tests/Critical/MissingCheckScanf/test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,27 @@ void switch_cases(const char *data) {
553553
break;
554554
}
555555
}
556+
557+
void test_scanf_compared_right_away() {
558+
int i;
559+
bool success = scanf("%d", &i) == 1;
560+
if(success) {
561+
use(i); // GOOD [FALSE POSITIVE]
562+
}
563+
}
564+
565+
void test_scanf_compared_in_conjunct_right(bool b) {
566+
int i;
567+
bool success = b && scanf("%d", &i) == 1;
568+
if(success) {
569+
use(i); // GOOD [FALSE POSITIVE]
570+
}
571+
}
572+
573+
void test_scanf_compared_in_conjunct_left(bool b) {
574+
int i;
575+
bool success = scanf("%d", &i) == 1 && b;
576+
if(success) {
577+
use(i); // GOOD [FALSE POSITIVE]
578+
}
579+
}

0 commit comments

Comments
 (0)