NetBSD Problem Report #58206

From www@netbsd.org  Sat Apr 27 23:43:26 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id CD07F1A9238
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 27 Apr 2024 23:43:25 +0000 (UTC)
Message-Id: <20240427234324.E664D1A923A@mollari.NetBSD.org>
Date: Sat, 27 Apr 2024 23:43:24 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: sync_with_stdio breaks reads from cin
X-Send-Pr-Version: www-1.0

>Number:         58206
>Category:       lib
>Synopsis:       sync_with_stdio breaks reads from cin
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 27 23:45:00 +0000 2024
>Closed-Date:    Fri Aug 23 21:08:54 +0000 2024
>Last-Modified:  Fri Aug 23 21:08:54 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9
>Organization:
The std::NetBSD++ Foundation
>Environment:
>Description:
In C++, std::ios::sync_with_stdio(false) has the side effect that reading from std::cin sets the eof|fail bits and does nothing to attempt a read from file descriptor 0.
>How-To-Repeat:
$ cat cin.cc
#include <iostream>

using std::cin;
using std::cout;

int
main(void)
{
	char buf[1024];

	std::ios::sync_with_stdio(false);
	cin.read(buf, sizeof buf);
	cout << "read " << cin.gcount() << " bytes, "
	     << "state " << cin.rdstate()
	     << " (eof|fail = " << (cin.eofbit|cin.failbit) << ")"
	     << std::endl;
	return 0;
}
$ make cin CXXFLAGS=-std=c++11
c++ -std=c++11   -o cin cin.cc 
$ echo foo | ./cin
read 0 bytes, state 6 (eof|fail = 6)

If I remove sync_with_stdio:

$ echo foo | ./cin
read 4 bytes, state 6 (eof|fail = 6)
>Fix:
Yes, please!

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58206 CVS commit: src
Date: Sun, 28 Apr 2024 01:21:27 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Apr 28 01:21:27 UTC 2024

 Modified Files:
 	src/distrib/sets/lists/debug: mi
 	src/distrib/sets/lists/tests: mi
 	src/etc/mtree: NetBSD.dist.tests
 Added Files:
 	src/tests/lib/libstdc++: Makefile h_cin_nosync.cc t_sync_with_stdio.sh

 Log Message:
 libstdc++: Add test for PR lib/58206, sync_with_stdio busted.


 To generate a diff of this commit:
 cvs rdiff -u -r1.432 -r1.433 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.1312 -r1.1313 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.203 -r1.204 src/etc/mtree/NetBSD.dist.tests
 cvs rdiff -u -r0 -r1.1 src/tests/lib/libstdc++/Makefile \
     src/tests/lib/libstdc++/h_cin_nosync.cc \
     src/tests/lib/libstdc++/t_sync_with_stdio.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Taylor R Campbell <riastradh@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/58206: sync_with_stdio breaks reads from cin
Date: Mon, 29 Apr 2024 19:37:26 +0000

 Followup change to fix build with new test in case of pullups:

 https://mail-index.netbsd.org/source-changes/2024/04/28/msg151018.html

From: "Leonardo Taccari" <leot@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58206 CVS commit: pkgsrc/security/git-crypt
Date: Sat, 4 May 2024 11:07:17 +0000

 Module Name:	pkgsrc
 Committed By:	leot
 Date:		Sat May  4 11:07:17 UTC 2024

 Modified Files:
 	pkgsrc/security/git-crypt: distinfo
 	pkgsrc/security/git-crypt/patches: patch-util.cpp

 Log Message:
 git-crypt: Reference PR lib/58206

 Seems exactly the same problem. Add a reference to it so once it is
 addressed we can wait a couple of years and G/C this patch too.


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 pkgsrc/security/git-crypt/distinfo
 cvs rdiff -u -r1.1 -r1.2 pkgsrc/security/git-crypt/patches/patch-util.cpp

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58206 CVS commit: src
Date: Mon, 20 May 2024 11:20:53 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon May 20 11:20:53 UTC 2024

 Modified Files:
 	src/external/gpl3/gcc/dist/libstdc++-v3/config/io: basic_file_stdio.cc
 	src/tests/lib/libstdc++: t_sync_with_stdio.sh

 Log Message:
 libstdc++: Don't try to fflush stdin.

 It doesn't work.  It's undefined behaviour.  On NetBSD, it will fail
 with EBADF, if fd 0 isn't open for write, or if fd 0 is open for
 write, it will write heap garbage to fd 0.

    If stream points to an output stream or an update stream in which
    the most recent operation was not input, the fflush function causes
    any unwritten data for that stream to be delivered to the host
    environment to be written to the file; otherwise, the behavior is
    undefined.

    (ISO C11 and ISO C17, Sec. 7.21.5.2 `The fflush function')

 PR lib/58206
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114879


 To generate a diff of this commit:
 cvs rdiff -u -r1.1.1.13 -r1.2 \
     src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc
 cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libstdc++/t_sync_with_stdio.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58206 CVS commit: src/external/gpl3/gcc.old/dist/libstdc++-v3/config/io
Date: Mon, 20 May 2024 19:36:30 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon May 20 19:36:30 UTC 2024

 Modified Files:
 	src/external/gpl3/gcc.old/dist/libstdc++-v3/config/io:
 	    basic_file_stdio.cc

 Log Message:
 libstdc++: Don't try to fflush stdin in gcc.old libstdc++ either.

 PR lib/58206
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114879


 To generate a diff of this commit:
 cvs rdiff -u -r1.13 -r1.14 \
     src/external/gpl3/gcc.old/dist/libstdc++-v3/config/io/basic_file_stdio.cc

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 23 Jul 2024 21:53:43 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-10 and pullup-9


State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sun, 18 Aug 2024 04:22:38 +0000
State-Changed-Why:
pullup-9 #1877 https://releng.netbsd.org/cgi-bin/req-9.cgi?show=1877
pullup-10 #801 https://releng.netbsd.org/cgi-bin/req-10.cgi?show=801


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58206 CVS commit: [netbsd-10] src
Date: Fri, 23 Aug 2024 18:28:10 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Aug 23 18:28:10 UTC 2024

 Modified Files:
 	src/distrib/sets/lists/debug [netbsd-10]: mi
 	src/distrib/sets/lists/tests [netbsd-10]: mi
 	src/etc/mtree [netbsd-10]: NetBSD.dist.tests
 	src/external/gpl3/gcc/dist/libstdc++-v3/config/io [netbsd-10]:
 	    basic_file_stdio.cc
 Added Files:
 	src/tests/lib/libstdc++ [netbsd-10]: Makefile h_cin_nosync.cc
 	    t_sync_with_stdio.sh

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #801):

 	tests/lib/libstdc++/h_cin_nosync.cc: revision 1.1
 	tests/lib/libstdc++/t_sync_with_stdio.sh: revision 1.1
 	tests/lib/libstdc++/t_sync_with_stdio.sh: revision 1.2
 	etc/mtree/NetBSD.dist.tests: revision 1.204
 	distrib/sets/lists/tests/mi: revision 1.1313
 	tests/lib/libstdc++/Makefile: revision 1.1
 	distrib/sets/lists/debug/mi: revision 1.433
 	external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc: revision 1.2

 libstdc++: Add test for PR lib/58206, sync_with_stdio busted.

 libstdc++: Don't try to fflush stdin.

 It doesn't work.  It's undefined behaviour.  On NetBSD, it will fail
 with EBADF, if fd 0 isn't open for write, or if fd 0 is open for
 write, it will write heap garbage to fd 0.

    If stream points to an output stream or an update stream in which
    the most recent operation was not input, the fflush function causes
    any unwritten data for that stream to be delivered to the host
    environment to be written to the file; otherwise, the behavior is
    undefined.
    (ISO C11 and ISO C17, Sec. 7.21.5.2 `The fflush function')

 PR lib/58206
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114879


 To generate a diff of this commit:
 cvs rdiff -u -r1.394.2.7 -r1.394.2.8 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.1238.2.7 -r1.1238.2.8 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.197.2.1 -r1.197.2.2 src/etc/mtree/NetBSD.dist.tests
 cvs rdiff -u -r1.1.1.12 -r1.1.1.12.6.1 \
     src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc
 cvs rdiff -u -r0 -r1.1.4.2 src/tests/lib/libstdc++/Makefile \
     src/tests/lib/libstdc++/h_cin_nosync.cc
 cvs rdiff -u -r0 -r1.2.4.2 src/tests/lib/libstdc++/t_sync_with_stdio.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58206 CVS commit: [netbsd-9] src
Date: Fri, 23 Aug 2024 18:32:37 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Aug 23 18:32:37 UTC 2024

 Modified Files:
 	src/distrib/sets/lists/debug [netbsd-9]: mi
 	src/distrib/sets/lists/tests [netbsd-9]: mi
 	src/etc/mtree [netbsd-9]: NetBSD.dist.tests
 	src/external/gpl3/gcc/dist/libstdc++-v3/config/io [netbsd-9]:
 	    basic_file_stdio.cc
 Added Files:
 	src/tests/lib/libstdc++ [netbsd-9]: Makefile h_cin_nosync.cc
 	    t_sync_with_stdio.sh

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #1877):

 	tests/lib/libstdc++/h_cin_nosync.cc: revision 1.1
 	tests/lib/libstdc++/t_sync_with_stdio.sh: revision 1.1
 	tests/lib/libstdc++/t_sync_with_stdio.sh: revision 1.2
 	etc/mtree/NetBSD.dist.tests: revision 1.204
 	distrib/sets/lists/tests/mi: revision 1.1313 (patch)
 	tests/lib/libstdc++/Makefile: revision 1.1
 	distrib/sets/lists/debug/mi: revision 1.433
 	external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc: revision 1.2

 libstdc++: Add test for PR lib/58206, sync_with_stdio busted.

 libstdc++: Don't try to fflush stdin.

 It doesn't work.  It's undefined behaviour.  On NetBSD, it will fail
 with EBADF, if fd 0 isn't open for write, or if fd 0 is open for
 write, it will write heap garbage to fd 0.

    If stream points to an output stream or an update stream in which
    the most recent operation was not input, the fflush function causes
    any unwritten data for that stream to be delivered to the host
    environment to be written to the file; otherwise, the behavior is
    undefined.
    (ISO C11 and ISO C17, Sec. 7.21.5.2 `The fflush function')

 PR lib/58206
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114879


 To generate a diff of this commit:
 cvs rdiff -u -r1.285.2.8 -r1.285.2.9 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.818.2.6 -r1.818.2.7 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.158 -r1.158.2.1 src/etc/mtree/NetBSD.dist.tests
 cvs rdiff -u -r1.1.1.7 -r1.1.1.7.2.1 \
     src/external/gpl3/gcc/dist/libstdc++-v3/config/io/basic_file_stdio.cc
 cvs rdiff -u -r0 -r1.1.6.2 src/tests/lib/libstdc++/Makefile \
     src/tests/lib/libstdc++/h_cin_nosync.cc
 cvs rdiff -u -r0 -r1.2.6.2 src/tests/lib/libstdc++/t_sync_with_stdio.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Fri, 23 Aug 2024 21:08:54 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 10, pulled up to 9
(and submitted upstream)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.