Skip to content

Commit

Permalink
Fix a toctou race condition (LinearTapeFileSystem#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atsushi Abe authored Oct 18, 2021
1 parent 6cdbad0 commit 4c3a760
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/libltfs/arch/arch_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ void show_runtime_system_info(void)
}
strcat(path, "/etc/");
strcat(path, dent->d_name);
if(stat(path, &stat_rel) != -1 && S_ISREG(stat_rel.st_mode)) {
fd = open(path, O_RDONLY);
if( fd == -1) {
ltfsmsg(LTFS_WARN, 17088W);
} else {
fd = open(path, O_RDONLY);
if( fd == -1) {
ltfsmsg(LTFS_WARN, 17088W);
} else {
if (fstat(fd, &stat_rel) != -1 && S_ISREG(stat_rel.st_mode)) {
memset(destribution, 0, sizeof(destribution));
read(fd, destribution, sizeof(destribution));
if((tmp = strchr(destribution, '\n')) != NULL)
*tmp = '\0';
ltfsmsg(LTFS_INFO, 17089I, destribution);
close(fd);
}

close(fd);
}
free(path);
}
Expand Down

0 comments on commit 4c3a760

Please sign in to comment.