mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
CPP: Add query for detecteing incorrect error checking for scanf
This commit is contained in:
30
cpp/ql/src/Critical/IncorrectCheckScanf.cpp
Normal file
30
cpp/ql/src/Critical/IncorrectCheckScanf.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
int i, j;
|
||||
|
||||
// BAD:The result is only checked against zero
|
||||
if (scanf("%d %d", &i, &j)) {
|
||||
use(i);
|
||||
use(j);
|
||||
}
|
||||
|
||||
// BAD: The result is only checked against zero
|
||||
if (scanf("%d %d", &i, &j) == 0) {
|
||||
i = 0;
|
||||
j = 0;
|
||||
}
|
||||
use(i);
|
||||
use(j);
|
||||
|
||||
if (scanf("%d %d", &i, &j) == 2) {
|
||||
// GOOD: the result is checked against 2
|
||||
}
|
||||
|
||||
// GOOD: the result is compared directly
|
||||
int r = scanf("%d %d", &i, &j);
|
||||
if (r < 2) {
|
||||
return;
|
||||
}
|
||||
if (r == 1) {
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user