mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
C++: Add close calls to examples for cpp/toctou-race-condition.
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
char *file_name;
|
||||
FILE *f_ptr;
|
||||
|
||||
|
||||
/* Initialize file_name */
|
||||
|
||||
|
||||
f_ptr = fopen(file_name, "w");
|
||||
if (f_ptr == NULL) {
|
||||
/* Handle error */
|
||||
}
|
||||
|
||||
|
||||
/* ... */
|
||||
|
||||
|
||||
if (chmod(file_name, S_IRUSR) == -1) {
|
||||
/* Handle error */
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f_ptr);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
char *file_name;
|
||||
int fd;
|
||||
|
||||
|
||||
/* Initialize file_name */
|
||||
|
||||
|
||||
fd = open(
|
||||
file_name,
|
||||
O_WRONLY | O_CREAT | O_EXCL,
|
||||
@@ -11,9 +11,11 @@ fd = open(
|
||||
if (fd == -1) {
|
||||
/* Handle error */
|
||||
}
|
||||
|
||||
|
||||
/* ... */
|
||||
|
||||
|
||||
if (fchmod(fd, S_IRUSR) == -1) {
|
||||
/* Handle error */
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
Reference in New Issue
Block a user