File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed
cpp/ql/test/experimental/query-tests/Security/CWE/CWE-754/semmle/tests Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ int globalVal;
3
3
char * globalVala;
4
4
int * globalValp;
5
5
char globalVala2;
6
- int functionWork1 () {
6
+ int functionWork1 (int retIndex ) {
7
7
int i;
8
8
char a[10 ];
9
9
int b;
@@ -14,10 +14,14 @@ int functionWork1() {
14
14
return -1 ;
15
15
if (scanf (" %i" , p) != 1 ) // GOOD
16
16
return -1 ;
17
+ if (retIndex == 0 )
18
+ return (int )a;
19
+ if (retIndex == 1 )
20
+ return *p;
17
21
return i;
18
22
}
19
23
20
- int functionWork1_ () {
24
+ int functionWork1_ (int retIndex ) {
21
25
int i;
22
26
char a[10 ];
23
27
int b;
@@ -32,6 +36,10 @@ int functionWork1_() {
32
36
r = scanf (" %i" , p);
33
37
if (r != 1 ) // GOOD
34
38
return -1 ;
39
+ if (retIndex == 0 )
40
+ return (int )a;
41
+ if (retIndex == 1 )
42
+ return *p;
35
43
return i;
36
44
}
37
45
@@ -49,19 +57,29 @@ int functionWork1b(int retIndex) {
49
57
return *p;
50
58
return i;
51
59
}
52
-
53
- int functionWork2 () {
60
+ int functionWork1_ () {
61
+ int i;
62
+ scanf (" %i" ,&i);
63
+ if (i<10 )
64
+ return -1 ;
65
+ return i;
66
+ }
67
+ int functionWork2 (int retIndex) {
54
68
int i = 0 ;
55
69
char a[10 ] = " " ;
56
70
int b = 1 ;
57
71
int *p = &b;
58
72
scanf (" %i" , &i); // GOOD:Argument initialized even when scanf fails.
59
73
scanf (" %s" , a); // GOOD:Argument initialized even when scanf fails.
60
74
scanf (" %i" , p); // GOOD:Argument initialized even when scanf fails.
75
+ if (retIndex == 0 )
76
+ return (int )a;
77
+ if (retIndex == 1 )
78
+ return *p;
61
79
return i;
62
80
}
63
81
64
- int functionWork2_ () {
82
+ int functionWork2_ (int retIndex ) {
65
83
int i;
66
84
i = 0 ;
67
85
char a[10 ];
@@ -72,6 +90,10 @@ int functionWork2_() {
72
90
scanf (" %i" , &i); // GOOD:Argument initialized even when scanf fails.
73
91
scanf (" %s" , a); // GOOD:Argument initialized even when scanf fails.
74
92
scanf (" %i" , p); // GOOD:Argument initialized even when scanf fails.
93
+ if (retIndex == 0 )
94
+ return (int )a;
95
+ if (retIndex == 1 )
96
+ return *p;
75
97
return i;
76
98
}
77
99
int functionWork2b () {
You can’t perform that action at this time.
0 commit comments