Reported in 2014 here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=761300 Rediscovered again: https://stackoverflow.com/a/53981648/50617 Trivial test: #include <stdio.h> int main (int argc, char *argv[]) { stdout = fopen ("/dev/null", "w"); printf ("argc = %d\n", argc); // Goes to /dev/null as expected putchar ('a'); // Goes to terminal (bug) puts("bcd"); // Likewise return 0; } gcc -g f.c && ./a.out abcd Verified this is still a problem with current trunk (7628a1b05adb1e4c6857b87c6f8b71a1d0b1d72c).
The same problem exists for stdin / getchar() and gets().
Paul, do you plan to work on this? Please also fix the wide versions at the same time if possible. Thanks.
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, master has been updated via 5f10701fdc7a4708101f7931c15b7146c4f06690 (commit) from 583dd860d5b833037175247230a328f0050dbfe9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5f10701fdc7a4708101f7931c15b7146c4f06690 commit 5f10701fdc7a4708101f7931c15b7146c4f06690 Author: Paul Pluzhnikov <ppluzhnikov@google.com> Date: Mon Dec 31 19:14:28 2018 -0800 libio: use stdout in puts and putchar, etc [BZ #24051]. GLIBC explicitly allows one to assign a new FILE pointer to stdout and other standard streams. printf and wprintf were honouring assignment to stdout and using the new value, but puts, putchar, and wide char variants did not. The stdout part is fixed here. The stdin part will be fixed in a followup. ----------------------------------------------------------------------- Summary of changes: ChangeLog | 13 ++++++++ libio/Makefile | 2 +- libio/fileops.c | 8 ++-- libio/ioputs.c | 12 ++++---- libio/putchar.c | 6 ++-- libio/putchar_u.c | 4 +- libio/putwchar.c | 6 ++-- libio/putwchar_u.c | 4 +- libio/tst-bz24051.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ libio/wfileops.c | 8 ++-- 10 files changed, 119 insertions(+), 25 deletions(-) create mode 100644 libio/tst-bz24051.c
Fixed in glibc 2.30.