Subject: bug#25692: [PATCH] sed fails testsuite/panic-tests when tty is not owned by current user

From: Kent Fredric <[email-masked]>
Date: Sun, 12 Feb 2017 01:45:27 +1300

If the tty is owned by a privileged user, and that privileged user is building
sed after changing UID, the state of the tty's may look as follows:

> tty
/dev/pts/9

> ls -la $(tty)
crw--w---- 1 root tty 136, 9 Feb 12 01:27 /dev/pts/9

> whoami
builder

> if [[ -r $(tty) ]]; then echo "readable"; else echo "not readable"; fi
not readable

This leads to the test producing the following diff:

FAIL: testsuite/panic-tests
===========================

--- exp-err-tty 2017-01-06 15:42:36.073141748 +1300
+++ err-tty     2017-01-06 15:42:36.086141949 +1300
@@ -1 +1 @@
-sed: couldn't edit X: is a terminal
+sed: can't read /dev/pts/3: Permission denied
FAIL testsuite/panic-tests.sh (exit status: 1)

And failing.

This failure makes sense however, and there's no sane way I know of to
make the terminal readable, other than demanding sed run the test
inside a pty it created.

So an effective workaround is just guard the test with a -r check
like it presently has for -w , because the tty dev can't be read for
sed to decide "its a tty" in this condition.

Tested patch that adds this trivial check attached.

Thanks.

---
Downstream Bug: https://bugs.gentoo.org/show_bug.cgi?id=604798
From 0fa312e2052e293ffca338fa0f4fa71eb3bc5239 Mon Sep 17 00:00:00 2001
From: Kent Fredric <[email-masked]>
Date: Sun, 8 Jan 2017 14:36:32 +1300
Subject: [PATCH] Ensure tty device is readable before running test

Unreadable tty's fail with a different permissions error
instead of failing with "is a tty" error.
---
 testsuite/panic-tests.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testsuite/panic-tests.sh b/testsuite/panic-tests.sh
index a2dba00..00a7090 100644
--- a/testsuite/panic-tests.sh
+++ b/testsuite/panic-tests.sh
@@ -87,7 +87,7 @@ EOF
 
 ttydev=no-such-file
 type tty >/dev/null 2>&1 && ttydev=$(tty 2>/dev/null)
-if test -w "$ttydev" ; then
+if test -w "$ttydev" && test -r "$ttydev" ; then
     returns_ 4 sed -i = "$ttydev" 2>err-tty || fail=1
 
     # remove the actual terminal device name (using sed itself...)
-- 
2.11.0