Skip to content

Commit 1e88470

Browse files
authored
Add files via upload
1 parent 9f4b725 commit 1e88470

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.cpp:20:3:20:8 | call to fclose | Second call to the $@ function is possible. | test.cpp:21:3:21:8 | call to fclose | fclose |
2+
| test.cpp:31:3:31:8 | call to fclose | Second call to the $@ function is possible. | test.cpp:32:3:32:8 | call to fclose | fclose |
3+
| test.cpp:38:3:38:8 | call to fclose | Second call to the $@ function is possible. | test.cpp:44:3:44:8 | call to fclose | fclose |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE/CWE-675/DoubleRelease.ql
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#define NULL (0)
2+
typedef int FILE;
3+
FILE *fopen(const char *filename, const char *mode);
4+
int fclose(FILE *stream);
5+
extern FILE * fe;
6+
void test1()
7+
{
8+
FILE *f;
9+
10+
f = fopen("myFile.txt", "wt");
11+
fclose(f); // GOOD
12+
f = NULL;
13+
}
14+
15+
void test2()
16+
{
17+
FILE *f;
18+
19+
f = fopen("myFile.txt", "wt");
20+
fclose(f); // BAD
21+
fclose(f);
22+
}
23+
24+
void test3()
25+
{
26+
FILE *f;
27+
FILE *g;
28+
29+
f = fopen("myFile.txt", "wt");
30+
g = f;
31+
fclose(f); // BAD
32+
fclose(g);
33+
}
34+
35+
int fGtest4_1()
36+
{
37+
fe = fopen("myFile.txt", "wt");
38+
fclose(fe); // BAD
39+
return -1;
40+
}
41+
42+
int fGtest4_2()
43+
{
44+
fclose(fe);
45+
return -1;
46+
}
47+
48+
void Gtest4()
49+
{
50+
fGtest4_1();
51+
fGtest4_2();
52+
}
53+
54+
int fGtest5_1()
55+
{
56+
fe = fopen("myFile.txt", "wt");
57+
fclose(fe); // GOOD
58+
fe = NULL;
59+
return -1;
60+
}
61+
62+
int fGtest5_2()
63+
{
64+
fclose(fe);
65+
return -1;
66+
}
67+
68+
void Gtest5()
69+
{
70+
fGtest5_1();
71+
fGtest5_2();
72+
}
73+
74+
int main(int argc, char *argv[])
75+
{
76+
test1();
77+
test2();
78+
test3();
79+
80+
Gtest4();
81+
Gtest5();
82+
return 0;
83+
}

0 commit comments

Comments
 (0)