Skip to content

Commit bc3b347

Browse files
committed
C++: Another test case to consider.
1 parent a53b161 commit bc3b347

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-367/semmle/TOCTOUFilesystemRace.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
| test2.cpp:98:7:98:11 | call to fopen | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:98:13:98:16 | path | filename | test2.cpp:96:15:96:17 | foo | checked |
55
| test2.cpp:157:7:157:10 | call to open | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:157:12:157:15 | path | filename | test2.cpp:155:6:155:9 | call to stat | checked |
66
| test2.cpp:170:7:170:10 | call to open | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:170:12:170:15 | path | filename | test2.cpp:168:6:168:10 | call to lstat | checked |
7-
| test2.cpp:229:3:229:7 | call to chmod | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:229:9:229:12 | path | filename | test2.cpp:222:6:222:10 | call to fopen | checked |
8-
| test2.cpp:239:3:239:8 | call to remove | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:239:10:239:14 | path1 | filename | test2.cpp:237:7:237:12 | call to rename | checked |
9-
| test2.cpp:261:7:261:11 | call to fopen | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:261:13:261:16 | path | filename | test2.cpp:259:6:259:11 | call to access | checked |
10-
| test2.cpp:287:7:287:11 | call to fopen | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:287:13:287:16 | path | filename | test2.cpp:285:7:285:12 | call to access | checked |
11-
| test2.cpp:301:7:301:11 | call to fopen | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:301:13:301:16 | path | filename | test2.cpp:297:6:297:11 | call to access | checked |
7+
| test2.cpp:245:3:245:7 | call to chmod | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:245:9:245:12 | path | filename | test2.cpp:238:6:238:10 | call to fopen | checked |
8+
| test2.cpp:255:3:255:8 | call to remove | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:255:10:255:14 | path1 | filename | test2.cpp:253:7:253:12 | call to rename | checked |
9+
| test2.cpp:277:7:277:11 | call to fopen | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:277:13:277:16 | path | filename | test2.cpp:275:6:275:11 | call to access | checked |
10+
| test2.cpp:303:7:303:11 | call to fopen | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:303:13:303:16 | path | filename | test2.cpp:301:7:301:12 | call to access | checked |
11+
| test2.cpp:317:7:317:11 | call to fopen | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test2.cpp:317:13:317:16 | path | filename | test2.cpp:313:6:313:11 | call to access | checked |
1212
| test.cpp:21:3:21:8 | call to remove | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test.cpp:21:10:21:14 | file1 | filename | test.cpp:19:7:19:12 | call to rename | checked |
1313
| test.cpp:35:3:35:8 | call to remove | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test.cpp:35:10:35:14 | file1 | filename | test.cpp:32:7:32:12 | call to rename | checked |
1414
| test.cpp:49:3:49:8 | call to remove | The $@ being operated upon was previously $@, but the underlying file may have been changed since then. | test.cpp:49:10:49:14 | file1 | filename | test.cpp:47:7:47:12 | call to rename | checked |

cpp/ql/test/query-tests/Security/CWE/CWE-367/semmle/test2.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,23 @@ void test2_10(int dir, const char *path, int arg)
199199
// ...
200200
}
201201

202-
void test2_11(const char *path, int arg)
202+
// --- open -> stat ---
203+
204+
void test3_1(const char *path, int arg)
205+
{
206+
stat_data buf;
207+
int f;
208+
209+
f = open(path, arg);
210+
if (stat(path, &buf)) // BAD??? [NOT DETECTED]
211+
{
212+
// ...
213+
}
214+
215+
// ...
216+
}
217+
218+
void test3_2(const char *path, int arg)
203219
{
204220
stat_data buf;
205221
int f;

0 commit comments

Comments
 (0)