From: Jim Meyering Date: Tue, 13 Nov 2001 10:14:12 +0000 (+0000) Subject: `tail /proc/ksyms' would segfault on Linux. X-Git-Tag: TEXTUTILS-2_0_17~90 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5579ee544c18c78176474c1a0266ec25630e0980;p=thirdparty%2Fcoreutils.git `tail /proc/ksyms' would segfault on Linux. (tail_lines): Use status of lseek (...SEEK_END) call in deciding whether to call file_lines or pipe_lines. From Herbert Xu. --- diff --git a/src/tail.c b/src/tail.c index 4973ef64bd..375e6316bd 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1095,14 +1095,14 @@ tail_lines (const char *pretty_filename, int fd, long int n_lines) { /* Use file_lines only if FD refers to a regular file with its file pointer positioned at beginning of file. */ - /* FIXME: adding the lseek conjunct is a kludge. + /* FIXME: this first lseek conjunct is a kludge. Once there's a reasonable test suite, fix the true culprit: file_lines. file_lines shouldn't presume that the input file pointer is initially positioned to beginning of file. */ if (S_ISREG (stats.st_mode) - && lseek (fd, (off_t) 0, SEEK_CUR) == (off_t) 0) + && lseek (fd, (off_t) 0, SEEK_CUR) == (off_t) 0 + && (length = lseek (fd, (off_t) 0, SEEK_END)) >= 0) { - length = lseek (fd, (off_t) 0, SEEK_END); if (length != 0 && file_lines (pretty_filename, fd, n_lines, length)) return 1; }