From 9f270dacbfb8f94fa7699fcbcb12e30c06c02b9d Mon Sep 17 00:00:00 2001 From: Alexandre Bruyelles Date: Tue, 5 Dec 2023 20:40:36 +0100 Subject: [PATCH] file_scan: prevent a bad close(2) on early error 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 --- file_scan.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/file_scan.c b/file_scan.c index 3189c8ca5b23..7b71e09c9a50 100644 --- a/file_scan.c +++ b/file_scan.c @@ -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)) {