CPP: Add query for detecteing incorrect error checking for scanf

This commit is contained in:
Alex Eyers-Taylor
2023-11-24 14:49:20 +00:00
parent 8334c6db91
commit f48e8b6062
4 changed files with 133 additions and 0 deletions

View File

@@ -429,3 +429,21 @@ void scan_and_static_variable() {
scanf("%d", &i);
use(i); // GOOD: static variables are always 0-initialized
}
void bad_check() {
{
int i = 0;
if (scanf("%d", &i) != 0) {
return;
}
use(i); // GOOD [FALSE POSITIVE]: Technically no security issue, but code is incorrect.
}
{
int i = 0;
int r = scanf("%d", &i);
if (!r) {
return;
}
use(i); // GOOD [FALSE POSITIVE]: Technically no security issue, but code is incorrect.
}
}