From b99731ec2c839a5fcb1fe18ddb4657ceb67a196a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 19 Apr 2026 11:00:43 -0700 Subject: [PATCH] tests: add a test for the just-fixed bug * testsuite/read-error-stale-errno.sh: New file. * testsuite/local.mk (T): Add it. --- testsuite/local.mk | 1 + testsuite/read-error-stale-errno.sh | 64 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 testsuite/read-error-stale-errno.sh diff --git a/testsuite/local.mk b/testsuite/local.mk index f5817c0..c350c49 100644 --- a/testsuite/local.mk +++ b/testsuite/local.mk @@ -85,6 +85,7 @@ T = \ testsuite/posix-mode-s.sh \ testsuite/posix-mode-N.sh \ testsuite/range-overlap.sh \ + testsuite/read-error-stale-errno.sh \ testsuite/recursive-escape-c.sh \ testsuite/regex-errors.sh \ testsuite/regex-max-int.sh \ diff --git a/testsuite/read-error-stale-errno.sh b/testsuite/read-error-stale-errno.sh new file mode 100755 index 0000000..acca7d4 --- /dev/null +++ b/testsuite/read-error-stale-errno.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Verify ck_getdelim no longer reports a misleading strerror(errno) +# when ferror is already set from a prior I/O operation. + +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed +print_ver_ sed + +# Use a FIFO with non-blocking I/O. After sed reads one line, +# the next read(2) fails with EAGAIN (not EOF, since a writer is +# still attached), setting ferror on the stream. +# +# With sed -s, test_eof's getc triggers EAGAIN, setting ferror; +# ck_getdelim is then called with ferror already set. +# +# Before the fix: "sed: read error on stdin: Resource temporarily unavailable" +# After the fix: "sed: read error on stdin" + +mkfifo fifo || framework_failure_ + +# A writer that keeps the FIFO's write-end open. +{ printf 'hello\n'; exec sleep 99; } > fifo & +writer_pid=$! + +# "dd iflag=nonblock count=0" sets O_NONBLOCK on the file description +# underlying stdin (a no-op read that just changes the flag). +# That flag is then inherited by sed. +# Skip if dd doesn't support iflag=nonblock. +( + exec < fifo + dd iflag=nonblock count=0 2>/dev/null || exit 77 + sed -s -n '$p' +) 2>err +rc=$? + +kill $writer_pid 2>/dev/null +wait + +test $rc -eq 77 && skip_ "dd does not support iflag=nonblock" + +# sed should have panicked (exit 4) due to the read error. +test $rc -eq 4 || fail=1 + +# The error message must mention "read error" ... +grep 'read error' err > /dev/null || fail=1 + +# ... but must NOT include a ": strerror" suffix, which would be misleading +# (before the fix, this was e.g., ": Resource temporarily unavailable"). +grep 'read error.*: ' err && fail=1 + +Exit $fail