NetBSD Problem Report #39574
From www@NetBSD.org Wed Sep 17 22:23:35 2008
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id 102B963B877
for <gnats-bugs@gnats.netbsd.org>; Wed, 17 Sep 2008 22:23:35 +0000 (UTC)
Message-Id: <20080917222334.AF7C963B842@narn.NetBSD.org>
Date: Wed, 17 Sep 2008 22:23:34 +0000 (UTC)
From: eravin@panix.com
Reply-To: eravin@panix.com
To: gnats-bugs@NetBSD.org
Subject: /bin/echo always exits zero even when it encounters I/O errors
X-Send-Pr-Version: www-1.0
>Number: 39574
>Category: bin
>Synopsis: /bin/echo always exits zero even when it encounters I/O errors
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: dholland
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Sep 17 22:25:00 +0000 2008
>Closed-Date: Wed Nov 19 05:46:12 +0000 2008
>Last-Modified: Wed Nov 19 05:46:12 +0000 2008
>Originator: Ed Ravin
>Release: 4.0
>Organization:
Public Access Networks Corp
>Environment:
NetBSD panix5.panix.com 4.0 NetBSD 4.0 (PANIX-XEN3U-USER) #1: Tue Apr 1 23:24:49 EDT 2008 root@juggler.panix.com:/misc2/obj/misc2/devel/netbsd/4.0/src/sys/arch/i386/compile/PANIX-XEN3U-USER i386
>Description:
We are having trouble with a shell script that loops on stdin, prompting users for information, that goes into infinite loop when the tty is revoked.
One of the problems seems to be that /bin/echo always exits with zero, even if it encounters I/O errors trying to write to stdout. This is bad practice, and it also contravenes the documentation:
EXIT STATUS
The echo utility exits 0 on success, and >0 if an error occurs.
>How-To-Repeat:
Confirmed by reading src/bin/echo.c (a very short program) that the return value from printf() and putchar() is never checked and that it always exits with zero.
>Fix:
>Release-Note:
>Audit-Trail:
From: Ed Ravin <eravin@panix.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/39574: /bin/echo always exits zero even when it encounters
I/O errors
Date: Wed, 17 Sep 2008 22:18:53 -0400
On Wed, Sep 17, 2008 at 10:25:00PM +0000, gnats-admin@netbsd.org wrote:
> >Category: bin
> >Responsible: bin-bug-people
> >Synopsis: /bin/echo always exits zero even when it encounters I/O errors
> >Arrival-Date: Wed Sep 17 22:25:00 +0000 2008
This might be a patch to fix the problem:
--- echo.c 2003-11-24 22:40:18.000000000 -0500
+++ echoiochk.c 2008-09-17 22:17:06.000000000 -0400
@@ -65,12 +65,13 @@
nflag = 0;
while (*argv) {
- (void)printf("%s", *argv);
+ if (printf("%s", *argv) < 0) exit(1);
if (*++argv)
- (void)putchar(' ');
+ if (putchar(' ') == EOF) exit(1);
+
}
if (nflag == 0)
- (void)putchar('\n');
+ if (putchar('\n') == EOF) exit(1);
exit(0);
/* NOTREACHED */
}
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/39574 CVS commit: src/bin/echo
Date: Thu, 18 Sep 2008 05:42:08 +0000 (UTC)
Module Name: src
Committed By: dholland
Date: Thu Sep 18 05:42:08 UTC 2008
Modified Files:
src/bin/echo: echo.c
Log Message:
Check ferror(stdout) and exit(1) if there's been a problem.
Fixes PR bin/39574 from Ed Ravin, but with a simpler patch.
To generate a diff of this commit:
cvs rdiff -r1.17 -r1.18 src/bin/echo/echo.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->pending-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Thu, 18 Sep 2008 05:52:04 +0000
State-Changed-Why:
Fixed in -current. I want to make sure it doesn't make the world explode
before filing the pullup.
State-Changed-From-To: pending-pullups->analyzed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 12 Oct 2008 01:41:34 +0000
State-Changed-Why:
overoptimistic.
Responsible-Changed-From-To: bin-bug-people->dholland
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Sun, 12 Oct 2008 01:42:17 +0000
Responsible-Changed-Why:
I've been handling it.
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/39574 CVS commit: src/bin/sh
Date: Sun, 12 Oct 2008 01:40:37 +0000 (UTC)
Module Name: src
Committed By: dholland
Date: Sun Oct 12 01:40:37 UTC 2008
Modified Files:
src/bin/sh: output.c output.h
src/bin/sh/bltin: bltin.h echo.c
Log Message:
output.c output.h: expose OUTPUT_ERR (flag for an exposed flags variable)
bltin.h: support ferror()
echo.c: use ferror() to fail on output write errors
Another piece of PR bin/39574.
To generate a diff of this commit:
cvs rdiff -r1.29 -r1.30 src/bin/sh/output.c
cvs rdiff -r1.18 -r1.19 src/bin/sh/output.h
cvs rdiff -r1.12 -r1.13 src/bin/sh/bltin/bltin.h
cvs rdiff -r1.13 -r1.14 src/bin/sh/bltin/echo.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: analyzed->pending-pullups
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 09 Nov 2008 05:06:06 +0000
State-Changed-Why:
Both changes filed as pullup-4 #1232. I think I'm not going to request
pullup to 3.x; if anyone needs it (or wants to test it) let me know.
From: Manuel Bouyer <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/39574 CVS commit: [netbsd-4] src/bin
Date: Tue, 18 Nov 2008 22:17:04 +0000 (UTC)
Module Name: src
Committed By: bouyer
Date: Tue Nov 18 22:17:04 UTC 2008
Modified Files:
src/bin/echo [netbsd-4]: echo.c
src/bin/sh [netbsd-4]: output.c output.h
src/bin/sh/bltin [netbsd-4]: bltin.h echo.c
Log Message:
Pull up following revision(s) (requested by dholland in ticket #1232):
bin/echo/echo.c: revision 1.18
bin/sh/bltin/bltin.h: revision 1.13
bin/sh/bltin/echo.c: revision 1.14
bin/sh/output.c: revision 1.30
bin/sh/output.h: revision 1.19
Check ferror(stdout) and exit(1) if there's been a problem.
Fixes PR bin/39574 from Ed Ravin, but with a simpler patch.
output.c output.h: expose OUTPUT_ERR (flag for an exposed flags variable)
bltin.h: support ferror()
echo.c: use ferror() to fail on output write errors
Another piece of PR bin/39574.
To generate a diff of this commit:
cvs rdiff -r1.15 -r1.15.16.1 src/bin/echo/echo.c
cvs rdiff -r1.29 -r1.29.4.1 src/bin/sh/output.c
cvs rdiff -r1.17 -r1.17.16.1 src/bin/sh/output.h
cvs rdiff -r1.11 -r1.11.16.1 src/bin/sh/bltin/bltin.h
cvs rdiff -r1.12 -r1.12.10.1 src/bin/sh/bltin/echo.c
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: dholland@NetBSD.org
State-Changed-When: Wed, 19 Nov 2008 05:46:12 +0000
State-Changed-Why:
Fixed and pulled up; thanks for reporting it.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.