From 308399a179a49b7b858c725de10177fdb0502fd2 Mon Sep 17 00:00:00 2001 From: Andre Albsmeier Date: Mon, 19 Aug 2024 10:54:24 +0300 Subject: [PATCH] tail -F: fix crash When show() detects an error and closes the file and follow() wants to close it again, a NULL dereference occurs. PR: 280910 MFC after: 1 week --- usr.bin/tail/forward.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index a5303385a74..6d9db94a827 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -379,7 +379,8 @@ follow(file_info_t *files, enum STYLE style, off_t off) sb2.st_dev != file->st.st_dev || sb2.st_nlink == 0) { show(file); - fclose(file->fp); + if (file->fp != NULL) + fclose(file->fp); file->fp = ftmp; memcpy(&file->st, &sb2, sizeof(struct stat));