Add files via upload

This commit is contained in:
ihsinme
2022-02-25 11:16:05 +03:00
committed by GitHub
parent bddb5fd9f9
commit 0c8a07218c
3 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
| test.cpp:23:3:23:7 | call to scanf | Unchecked return value for call to 'scanf'. |
| test.cpp:41:3:41:7 | call to scanf | Unchecked return value for call to 'scanf'. |

View File

@@ -0,0 +1 @@
experimental/Security/CWE/CWE-754/ImproperCheckReturnValueScanf.ql

View File

@@ -0,0 +1,53 @@
int scanf(const char *format, ...);
int globalVal;
int functionWork1() {
int i;
if (scanf("%i", i) == 1) // GOOD
return i;
else
return -1;
}
int functionWork1_() {
int i;
int r;
r = scanf("%i", i);
if (r == 1) // GOOD
return i;
else
return -1;
}
int functionWork1b() {
int i;
scanf("%i", i); // BAD
return i;
}
int functionWork2() {
int i = 0;
scanf("%i", i); // GOOD:the error can be determined by examining the initial value.
return i;
}
int functionWork2_() {
int i;
i = 0;
scanf("%i", i); // GOOD:the error can be determined by examining the initial value.
return i;
}
int functionWork2b() {
int i;
scanf("%i", i); // BAD
globalVal = i;
return 0;
}
void functionRunner() {
functionWork1();
functionWork1_();
functionWork1b();
functionWork2();
functionWork2_();
functionWork2b();
}