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;
33char * globalVala;
44int * globalValp;
55char globalVala2;
6- int functionWork1 () {
6+ int functionWork1 (int retIndex ) {
77 int i;
88 char a[10 ];
99 int b;
@@ -14,10 +14,14 @@ int functionWork1() {
1414 return -1 ;
1515 if (scanf (" %i" , p) != 1 ) // GOOD
1616 return -1 ;
17+ if (retIndex == 0 )
18+ return (int )a;
19+ if (retIndex == 1 )
20+ return *p;
1721 return i;
1822}
1923
20- int functionWork1_ () {
24+ int functionWork1_ (int retIndex ) {
2125 int i;
2226 char a[10 ];
2327 int b;
@@ -32,6 +36,10 @@ int functionWork1_() {
3236 r = scanf (" %i" , p);
3337 if (r != 1 ) // GOOD
3438 return -1 ;
39+ if (retIndex == 0 )
40+ return (int )a;
41+ if (retIndex == 1 )
42+ return *p;
3543 return i;
3644}
3745
@@ -49,19 +57,29 @@ int functionWork1b(int retIndex) {
4957 return *p;
5058 return i;
5159}
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) {
5468 int i = 0 ;
5569 char a[10 ] = " " ;
5670 int b = 1 ;
5771 int *p = &b;
5872 scanf (" %i" , &i); // GOOD:Argument initialized even when scanf fails.
5973 scanf (" %s" , a); // GOOD:Argument initialized even when scanf fails.
6074 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;
6179 return i;
6280}
6381
64- int functionWork2_ () {
82+ int functionWork2_ (int retIndex ) {
6583 int i;
6684 i = 0 ;
6785 char a[10 ];
@@ -72,6 +90,10 @@ int functionWork2_() {
7290 scanf (" %i" , &i); // GOOD:Argument initialized even when scanf fails.
7391 scanf (" %s" , a); // GOOD:Argument initialized even when scanf fails.
7492 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;
7597 return i;
7698}
7799int functionWork2b () {
You can’t perform that action at this time.
0 commit comments