Date: Mon, 19 Feb 2018 08:15:36 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 222671] tail(1): tail -r fails on certain piped input Message-ID: <bug-222671-8-W97Qunqay3@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-222671-8@https.bugs.freebsd.org/bugzilla/> References: <bug-222671-8@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D222671 pprocacci@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pprocacci@gmail.com --- Comment #2 from pprocacci@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 t= he buffer. *p is never checked to see if it is a newline while `start` is tru= e. 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 ca= se. 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 =3D=3D '\n') || start) { struct bfelem *tr; - if (start && llen) - WR(p, llen + 1); + if (start && llen){ + if(*p =3D=3D '\n') + WR(p + 1, llen); + else + WR(p, llen + 1); + } else if (llen) WR(p + 1, llen); tr =3D TAILQ_NEXT(tl, entries); --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-222671-8-W97Qunqay3>