From 6f30a99fa537adb029283cf2ef03cb4419350e6c Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Sun, 27 Nov 2016 13:00:35 +0000 Subject: tail: fix uninitialized memory read when failing to read file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproduced under UBSAN with `tail -f <&-` giving: tail.c:2220:18: runtime error: load of value 190, which is not a valid value for type ‘_Bool' * src/tail.c (tail_file): Ensure f->ignore is initialized in all cases where we can't tail the specified file. * tests/tail-2/follow-stdin.sh: Add a test case which checks stderr has no UBSAN warnings. Fixes http://bugs.gnu.org/25041 --- src/tail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/tail.c b/src/tail.c index 5c75be08d..6bf1e77d0 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1940,8 +1940,6 @@ tail_file (struct File_spec *f, uintmax_t n_units) ok = false; f->errnum = -1; f->tailable = false; - f->ignore = ! (reopen_inaccessible_files - && follow_mode == Follow_name); error (0, 0, _("%s: cannot follow end of this type of file%s"), quotef (pretty_name (f)), f->ignore ? _("; giving up on this name") : ""); @@ -1949,6 +1947,8 @@ tail_file (struct File_spec *f, uintmax_t n_units) if (!ok) { + f->ignore = ! (reopen_inaccessible_files + && follow_mode == Follow_name); close_fd (fd, pretty_name (f)); f->fd = -1; } -- cgit v1.2.3-54-g00ecf