https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222671

pproca...@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pproca...@gmail.com

--- Comment #2 from pproca...@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.
_______________________________________________
freebsd-bugs@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to