Skip to content

Commit 49bbfef

Browse files
committed
C++: Fix uses of 'rename' in tests.
1 parent c5ed859 commit 49bbfef

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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 |
77
| 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 |
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:6:253:11 | call to rename | checked |
99
| 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 |
1010
| 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 |
1111
| 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 |

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bool fstat(int file, stat_data *buf);
2020
bool lstat(const char *path, stat_data *buf);
2121
bool fstatat(int dir, const char *path, stat_data *buf);
2222
void chmod(const char *path, int setting);
23-
bool rename(const char *from, const char *to);
23+
int rename(const char *from, const char *to);
2424
bool remove(const char *path);
2525

2626
bool access(const char *path);
@@ -250,7 +250,7 @@ void test4_1(const char *path)
250250

251251
void test5_1(const char *path1, const char *path2)
252252
{
253-
if (!rename(path1, path2))
253+
if (rename(path1, path2))
254254
{
255255
remove(path1); // DUBIOUS (bad but perhaps not exploitable) [REPORTED]
256256
}
@@ -260,7 +260,7 @@ void test5_2(const char *path1, const char *path2)
260260
{
261261
FILE *f = NULL;
262262

263-
if (rename(path1, path2))
263+
if (!rename(path1, path2))
264264
{
265265
f = fopen(path2, "r"); // BAD [NOT DETECTED]
266266
}

0 commit comments

Comments
 (0)