* NEWS: Mention the bug fix.
* src/comm.c (compare_files): Only close standard input once.
* tests/comm/dash-dash.sh: New file.
* tests/misc/comm.pl: Move to tests/comm/comm.pl.
* tests/local.mk (all_tests): Add the new test. Rename the existing
test.
---
NEWS | 6 ++++++
src/comm.c | 4 +++-
tests/{misc => comm}/comm.pl | 0
tests/comm/dash-dash.sh | 29 +++++++++++++++++++++++++++++
tests/local.mk | 3 ++-
5 files changed, 40 insertions(+), 2 deletions(-)
rename tests/{misc => comm}/comm.pl (100%)
create mode 100755 tests/comm/dash-dash.sh
diff --git a/NEWS b/NEWS
index 038a1b520..a827cf0d9 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,12 @@ GNU coreutils NEWS -*-
outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ 'comm - -' no longer closes standard input twice. Previously it would
+ mistakenly exit with a nonzero status.
+ [This bug was present in "the beginning".]
+
* Noteworthy changes in release 9.11 (2026-04-20) [stable]
diff --git a/src/comm.c b/src/comm.c
index 8e671f40d..ff5a3fb9c 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -388,7 +388,9 @@ compare_files (char **infiles)
}
}
- for (int i = 0; i < 2; i++)
+ /* Avoid closing standard input twice when invoking 'comm - -'. */
+ const int n_streams = 2 - (streams[0] == streams[1]);
+ for (int i = 0; i < n_streams; i++)
if (fclose (streams[i]) != 0)
error (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
diff --git a/tests/misc/comm.pl b/tests/comm/comm.pl
similarity index 100%
rename from tests/misc/comm.pl
rename to tests/comm/comm.pl
diff --git a/tests/comm/dash-dash.sh b/tests/comm/dash-dash.sh
new file mode 100755
index 000000000..ee4842c15
--- /dev/null
+++ b/tests/comm/dash-dash.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Test that 'comm - -' works.
+
+# 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ comm
+
+# In coreutils 9.11 and earlier, running 'comm - -' would close
+# standard input twice, leading to an incorrect exit status.
+echo 'y' >exp || framework_failure_
+yes | head -n 1 | timeout 10 comm - - >out 2>err || fail=1
+compare exp out || fail=1
+compare /dev/null err || fail=1
+
+Exit $fail
diff --git a/tests/local.mk b/tests/local.mk
index 628e54436..fde3ea989 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -324,7 +324,8 @@ all_tests = \
tests/cksum/cksum-base64.pl \
tests/cksum/cksum-base64-untagged.sh \
tests/cksum/cksum-raw.sh \
- tests/misc/comm.pl \
+ tests/comm/comm.pl \
+ tests/comm/dash-dash.sh \
tests/csplit/csplit.sh \
tests/csplit/csplit-1000.sh \
tests/csplit/csplit-heap.sh \
--
2.53.0