From 0655b86a6ebc6f1324810d504a71803aa708d162 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Mon, 28 Nov 2016 17:11:18 +0000 Subject: head: fix processing of non-seekable input as seekable * src/head.c (elide_tail_bytes_file): Ensure we don't use st_size unless we've previously used seek() to determine the CURRENT_POS in the seekable file. This was seen to cause issue on FreeBSD 11 when the pipe buffer was filled with `yes | head --lines=-0`, in which case st_size was 64KiB while ST_BLKSIZE() was 4KiB. Reported by Assaf Gordon. --- src/head.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/head.c') diff --git a/src/head.c b/src/head.c index 21ace70b4..756c978c6 100644 --- a/src/head.c +++ b/src/head.c @@ -465,7 +465,7 @@ elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide, struct stat const *st, off_t current_pos) { off_t size = st->st_size; - if (presume_input_pipe || size <= ST_BLKSIZE (*st)) + if (presume_input_pipe || current_pos < 0 || size <= ST_BLKSIZE (*st)) return elide_tail_bytes_pipe (filename, fd, n_elide, current_pos); else { @@ -754,7 +754,7 @@ elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide, struct stat const *st, off_t current_pos) { off_t size = st->st_size; - if (presume_input_pipe || size <= ST_BLKSIZE (*st)) + if (presume_input_pipe || current_pos < 0 || size <= ST_BLKSIZE (*st)) return elide_tail_lines_pipe (filename, fd, n_elide, current_pos); else { -- cgit v1.2.3-54-g00ecf