From 4ee8ea5ef8d23857959b42150fd2b6d34ab37ba0 Mon Sep 17 00:00:00 2001 From: jilles Date: Sun, 21 Aug 2011 20:59:51 +0000 Subject: [PATCH] MFC r224865: tail: Fix crash if -F'ed file's filesystem disappears. If tail notices that a file it is following no longer exists (because stat() fails), it will output any final lines and then close the file. If the read operation also causes an error, such as when the filesystem is forcefully unmounted, it closes the file as well, leading to fclose(NULL) and a segmentation fault. PR: bin/159750 git-svn-id: svn://svn.freebsd.org/base/stable/8@225067 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/tail/forward.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index 6dab72ed0..2e69d0654 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -365,8 +365,10 @@ follow(file_info_t *files, enum STYLE style, off_t off) if (errno != ENOENT) ierr(file->file_name); show(file); - fclose(file->fp); - file->fp = NULL; + if (file->fp != NULL) { + fclose(file->fp); + file->fp = NULL; + } ev_change++; continue; } -- 2.45.0