7e86df
From 89341f87f9fc65c4d7133e497bb04586e86b8052 Mon Sep 17 00:00:00 2001
7e86df
From: Tony Cook <tony@develop-help.com>
7e86df
Date: Tue, 12 May 2020 10:29:17 +1000
7e86df
Subject: [PATCH 1/2] make $fh->error report errors from both input and output
7e86df
MIME-Version: 1.0
7e86df
Content-Type: text/plain; charset=UTF-8
7e86df
Content-Transfer-Encoding: 8bit
7e86df
7e86df
For character devices and sockets perl uses separate PerlIO objects
7e86df
for input and output so they can be buffered separately.
7e86df
7e86df
The IO::Handle::error() method only checked the input stream, so
7e86df
if a write error occurs error() would still returned false.
7e86df
7e86df
Change this so both the input and output streams are checked.
7e86df
7e86df
fixes #6799
7e86df
7e86df
Signed-off-by: Petr Písař <ppisar@redhat.com>
7e86df
---
7e86df
 dist/IO/IO.xs     | 12 ++++++++----
7e86df
 dist/IO/t/io_xs.t | 19 ++++++++++++++++++-
7e86df
 2 files changed, 26 insertions(+), 5 deletions(-)
7e86df
7e86df
diff --git a/dist/IO/IO.xs b/dist/IO/IO.xs
7e86df
index 68b7352c38..99d523d2c1 100644
7e86df
--- a/dist/IO/IO.xs
7e86df
+++ b/dist/IO/IO.xs
7e86df
@@ -389,13 +389,17 @@ ungetc(handle, c)
7e86df
 
7e86df
 int
7e86df
 ferror(handle)
7e86df
-	InputStream	handle
7e86df
+	SV *	handle
7e86df
+    PREINIT:
7e86df
+        IO *io = sv_2io(handle);
7e86df
+        InputStream in = IoIFP(io);
7e86df
+        OutputStream out = IoOFP(io);
7e86df
     CODE:
7e86df
-	if (handle)
7e86df
+	if (in)
7e86df
 #ifdef PerlIO
7e86df
-	    RETVAL = PerlIO_error(handle);
7e86df
+	    RETVAL = PerlIO_error(in) || (in != out && PerlIO_error(out));
7e86df
 #else
7e86df
-	    RETVAL = ferror(handle);
7e86df
+	    RETVAL = ferror(in) || (in != out && ferror(out));
7e86df
 #endif
7e86df
 	else {
7e86df
 	    RETVAL = -1;
7e86df
diff --git a/dist/IO/t/io_xs.t b/dist/IO/t/io_xs.t
7e86df
index 1e3c49a4a7..f890e92558 100644
7e86df
--- a/dist/IO/t/io_xs.t
7e86df
+++ b/dist/IO/t/io_xs.t
7e86df
@@ -11,7 +11,7 @@ BEGIN {
7e86df
     }
7e86df
 }
7e86df
 
7e86df
-use Test::More tests => 5;
7e86df
+use Test::More tests => 7;
7e86df
 use IO::File;
7e86df
 use IO::Seekable;
7e86df
 
7e86df
@@ -50,3 +50,20 @@ SKIP:
7e86df
     ok($fh->sync, "sync to a read only handle")
7e86df
 	or diag "sync(): ", $!;
7e86df
 }
7e86df
+
7e86df
+
7e86df
+SKIP: {
7e86df
+    # gh 6799
7e86df
+    #
7e86df
+    # This isn't really a Linux/BSD specific test, but /dev/full is (I
7e86df
+    # hope) reasonably well defined on these.  Patches welcome if your platform
7e86df
+    # also supports it (or something like it)
7e86df
+    skip "no /dev/full or not a /dev/full platform", 2
7e86df
+      unless $^O =~ /^(linux|netbsd|freebsd)$/ && -c "/dev/full";
7e86df
+    open my $fh, ">", "/dev/full"
7e86df
+      or skip "Could not open /dev/full: $!", 2;
7e86df
+    $fh->print("a" x 1024);
7e86df
+    ok(!$fh->flush, "should fail to flush");
7e86df
+    ok($fh->error, "stream should be in error");
7e86df
+    close $fh; # silently ignore the error
7e86df
+}
7e86df
-- 
7e86df
2.25.4
7e86df