Skip to content

Commit 0c8a072

Browse files
authored
Add files via upload
1 parent bddb5fd commit 0c8a072

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:23:3:23:7 | call to scanf | Unchecked return value for call to 'scanf'. |
2+
| test.cpp:41:3:41:7 | call to scanf | Unchecked return value for call to 'scanf'. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-754/ImproperCheckReturnValueScanf.ql
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
int scanf(const char *format, ...);
2+
int globalVal;
3+
int functionWork1() {
4+
int i;
5+
if (scanf("%i", i) == 1) // GOOD
6+
return i;
7+
else
8+
return -1;
9+
}
10+
11+
int functionWork1_() {
12+
int i;
13+
int r;
14+
r = scanf("%i", i);
15+
if (r == 1) // GOOD
16+
return i;
17+
else
18+
return -1;
19+
}
20+
21+
int functionWork1b() {
22+
int i;
23+
scanf("%i", i); // BAD
24+
return i;
25+
}
26+
27+
int functionWork2() {
28+
int i = 0;
29+
scanf("%i", i); // GOOD:the error can be determined by examining the initial value.
30+
return i;
31+
}
32+
33+
int functionWork2_() {
34+
int i;
35+
i = 0;
36+
scanf("%i", i); // GOOD:the error can be determined by examining the initial value.
37+
return i;
38+
}
39+
int functionWork2b() {
40+
int i;
41+
scanf("%i", i); // BAD
42+
globalVal = i;
43+
return 0;
44+
}
45+
46+
void functionRunner() {
47+
functionWork1();
48+
functionWork1_();
49+
functionWork1b();
50+
functionWork2();
51+
functionWork2_();
52+
functionWork2b();
53+
}

0 commit comments

Comments
 (0)