Skip to content

Commit e294c8e

Browse files
authored
Merge pull request #17347 from paldepind/test-for-uninitialized-local
C++: Add test for cpp/uninitialized-local and va_copy
2 parents c082c25 + 660869e commit e294c8e

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/UninitializedLocal.expected

+22-22
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ edges
22
nodes
33
| test.cpp:11:6:11:8 | definition of foo | semmle.label | definition of foo |
44
| test.cpp:111:6:111:8 | definition of foo | semmle.label | definition of foo |
5-
| test.cpp:218:7:218:7 | definition of x | semmle.label | definition of x |
6-
| test.cpp:241:6:241:6 | definition of i | semmle.label | definition of i |
7-
| test.cpp:333:7:333:7 | definition of a | semmle.label | definition of a |
8-
| test.cpp:358:7:358:7 | definition of a | semmle.label | definition of a |
9-
| test.cpp:359:6:359:8 | definition of val | semmle.label | definition of val |
10-
| test.cpp:414:9:414:9 | definition of j | semmle.label | definition of j |
11-
| test.cpp:431:9:431:9 | definition of j | semmle.label | definition of j |
12-
| test.cpp:452:6:452:6 | definition of x | semmle.label | definition of x |
13-
| test.cpp:458:6:458:6 | definition of x | semmle.label | definition of x |
14-
| test.cpp:464:6:464:6 | definition of x | semmle.label | definition of x |
15-
| test.cpp:471:6:471:6 | definition of x | semmle.label | definition of x |
5+
| test.cpp:226:7:226:7 | definition of x | semmle.label | definition of x |
6+
| test.cpp:249:6:249:6 | definition of i | semmle.label | definition of i |
7+
| test.cpp:341:7:341:7 | definition of a | semmle.label | definition of a |
8+
| test.cpp:366:7:366:7 | definition of a | semmle.label | definition of a |
9+
| test.cpp:367:6:367:8 | definition of val | semmle.label | definition of val |
10+
| test.cpp:422:9:422:9 | definition of j | semmle.label | definition of j |
11+
| test.cpp:439:9:439:9 | definition of j | semmle.label | definition of j |
12+
| test.cpp:460:6:460:6 | definition of x | semmle.label | definition of x |
13+
| test.cpp:466:6:466:6 | definition of x | semmle.label | definition of x |
14+
| test.cpp:472:6:472:6 | definition of x | semmle.label | definition of x |
15+
| test.cpp:479:6:479:6 | definition of x | semmle.label | definition of x |
1616
#select
1717
| test.cpp:12:6:12:8 | foo | test.cpp:11:6:11:8 | definition of foo | test.cpp:11:6:11:8 | definition of foo | The variable $@ may not be initialized at this access. | test.cpp:11:6:11:8 | foo | foo |
1818
| test.cpp:113:6:113:8 | foo | test.cpp:111:6:111:8 | definition of foo | test.cpp:111:6:111:8 | definition of foo | The variable $@ may not be initialized at this access. | test.cpp:111:6:111:8 | foo | foo |
19-
| test.cpp:219:3:219:3 | x | test.cpp:218:7:218:7 | definition of x | test.cpp:218:7:218:7 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:218:7:218:7 | x | x |
20-
| test.cpp:243:13:243:13 | i | test.cpp:241:6:241:6 | definition of i | test.cpp:241:6:241:6 | definition of i | The variable $@ may not be initialized at this access. | test.cpp:241:6:241:6 | i | i |
21-
| test.cpp:336:10:336:10 | a | test.cpp:333:7:333:7 | definition of a | test.cpp:333:7:333:7 | definition of a | The variable $@ may not be initialized at this access. | test.cpp:333:7:333:7 | a | a |
22-
| test.cpp:369:10:369:10 | a | test.cpp:358:7:358:7 | definition of a | test.cpp:358:7:358:7 | definition of a | The variable $@ may not be initialized at this access. | test.cpp:358:7:358:7 | a | a |
23-
| test.cpp:378:9:378:11 | val | test.cpp:359:6:359:8 | definition of val | test.cpp:359:6:359:8 | definition of val | The variable $@ may not be initialized at this access. | test.cpp:359:6:359:8 | val | val |
24-
| test.cpp:417:10:417:10 | j | test.cpp:414:9:414:9 | definition of j | test.cpp:414:9:414:9 | definition of j | The variable $@ may not be initialized at this access. | test.cpp:414:9:414:9 | j | j |
25-
| test.cpp:436:9:436:9 | j | test.cpp:431:9:431:9 | definition of j | test.cpp:431:9:431:9 | definition of j | The variable $@ may not be initialized at this access. | test.cpp:431:9:431:9 | j | j |
26-
| test.cpp:454:2:454:2 | x | test.cpp:452:6:452:6 | definition of x | test.cpp:452:6:452:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:452:6:452:6 | x | x |
27-
| test.cpp:460:7:460:7 | x | test.cpp:458:6:458:6 | definition of x | test.cpp:458:6:458:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:458:6:458:6 | x | x |
28-
| test.cpp:467:2:467:2 | x | test.cpp:464:6:464:6 | definition of x | test.cpp:464:6:464:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:464:6:464:6 | x | x |
29-
| test.cpp:474:7:474:7 | x | test.cpp:471:6:471:6 | definition of x | test.cpp:471:6:471:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:471:6:471:6 | x | x |
19+
| test.cpp:227:3:227:3 | x | test.cpp:226:7:226:7 | definition of x | test.cpp:226:7:226:7 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:226:7:226:7 | x | x |
20+
| test.cpp:251:13:251:13 | i | test.cpp:249:6:249:6 | definition of i | test.cpp:249:6:249:6 | definition of i | The variable $@ may not be initialized at this access. | test.cpp:249:6:249:6 | i | i |
21+
| test.cpp:344:10:344:10 | a | test.cpp:341:7:341:7 | definition of a | test.cpp:341:7:341:7 | definition of a | The variable $@ may not be initialized at this access. | test.cpp:341:7:341:7 | a | a |
22+
| test.cpp:377:10:377:10 | a | test.cpp:366:7:366:7 | definition of a | test.cpp:366:7:366:7 | definition of a | The variable $@ may not be initialized at this access. | test.cpp:366:7:366:7 | a | a |
23+
| test.cpp:386:9:386:11 | val | test.cpp:367:6:367:8 | definition of val | test.cpp:367:6:367:8 | definition of val | The variable $@ may not be initialized at this access. | test.cpp:367:6:367:8 | val | val |
24+
| test.cpp:425:10:425:10 | j | test.cpp:422:9:422:9 | definition of j | test.cpp:422:9:422:9 | definition of j | The variable $@ may not be initialized at this access. | test.cpp:422:9:422:9 | j | j |
25+
| test.cpp:444:9:444:9 | j | test.cpp:439:9:439:9 | definition of j | test.cpp:439:9:439:9 | definition of j | The variable $@ may not be initialized at this access. | test.cpp:439:9:439:9 | j | j |
26+
| test.cpp:462:2:462:2 | x | test.cpp:460:6:460:6 | definition of x | test.cpp:460:6:460:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:460:6:460:6 | x | x |
27+
| test.cpp:468:7:468:7 | x | test.cpp:466:6:466:6 | definition of x | test.cpp:466:6:466:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:466:6:466:6 | x | x |
28+
| test.cpp:475:2:475:2 | x | test.cpp:472:6:472:6 | definition of x | test.cpp:472:6:472:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:472:6:472:6 | x | x |
29+
| test.cpp:482:7:482:7 | x | test.cpp:479:6:479:6 | definition of x | test.cpp:479:6:479:6 | definition of x | The variable $@ may not be initialized at this access. | test.cpp:479:6:479:6 | x | x |

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/test.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ int absCorrect2(int i) {
156156
return j; // correct: j always initialized before use
157157
}
158158

159+
typedef __builtin_va_list va_list;
160+
#define va_start(v, l) __builtin_va_start(v,l)
161+
#define va_end(v) __builtin_va_end(v)
162+
#define va_arg(v, l) __builtin_va_arg(v,l)
163+
#define va_copy(d, s) __builtin_va_copy(d,s)
159164

160-
typedef void *va_list;
161-
#define va_start(ap, parmN)
162-
#define va_end(ap)
163-
#define va_arg(ap, type) ((type)0)
164165
#define NULL 0
165166

166167
// Variadic initialisation
@@ -176,7 +177,7 @@ void init(int val, ...) {
176177
void test15() {
177178
int foo;
178179
init(42, &foo, NULL);
179-
use(foo); //GOOD -- initialised by `init`
180+
use(foo); // GOOD -- initialised by `init`
180181
}
181182

182183
// Variadic non-initialisation
@@ -192,6 +193,13 @@ void test16() {
192193
use(foo); // BAD (NOT REPORTED)
193194
}
194195

196+
void test_va_copy(va_list va) {
197+
va_list va2;
198+
va_copy(va2, va); // GOOD -- this is an initialization
199+
use(va2);
200+
va_end(va2);
201+
}
202+
195203
bool test17(bool b) {
196204
int foo;
197205
int *p = nullptr;

0 commit comments

Comments
 (0)