[Bug 222671] tail(1): tail -r fails on certain piped input
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Mon Feb 19 08:15:37 UTC 2018
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222671
pprocacci at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pprocacci at gmail.com
--- Comment #2 from pprocacci at gmail.com ---
The problem is in usr.bin/tail/reverse.c line 258.
The variable `start` is only true when the pointer is at the beginning of the
buffer. *p is never checked to see if it is a newline while `start` is true.
This has the effect of the following being written: '\n1\n'.
It does appear that the newline is randomly inserted, but this isn't the case.
It's essentially writing this:
write(1, '2\n', 2);
write(1, '\n1\n', 3);
Excuse the inline patch (too late in the morning to create an attachement).
The patch solves the problem by checking *p when start is true and fixes the
problem.
--- reverse.c.orig 2018-02-19 03:13:53.835943000 -0500
+++ reverse.c 2018-02-19 03:14:34.665507000 -0500
@@ -255,8 +255,12 @@
if ((*p == '\n') || start) {
struct bfelem *tr;
- if (start && llen)
- WR(p, llen + 1);
+ if (start && llen){
+ if(*p == '\n')
+ WR(p + 1, llen);
+ else
+ WR(p, llen + 1);
+ }
else if (llen)
WR(p + 1, llen);
tr = TAILQ_NEXT(tl, entries);
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list