Skip to content

Commit

Permalink
file_scan: prevent a bad close(2) on early error
Browse files Browse the repository at this point in the history
Without this change, fd is initiated as 0.
If an error occurs before we open(2) the file,
the cleanup code will try to close that unrelated file descriptor.

Signed-off-by: Alexandre Bruyelles <[email protected]>
  • Loading branch information
JackSlateur committed Dec 5, 2023
1 parent 17b7079 commit 9f270da
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions file_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,9 @@ static void csum_whole_file(struct file_to_scan *file)
*/
bool eof_reached = false;

/* Prevent close on fd 0 if, somehow, an error occurs before we open */
ctxt.fd = -1;

print_progress(file->file_position, file->path);

if (!(buffer.buf)) {
Expand Down

0 comments on commit 9f270da

Please sign in to comment.