NetBSD Problem Report #54885

From mouse@Stone.Rodents-Montreal.ORG  Thu Jan 23 05:32:12 2020
Return-Path: <mouse@Stone.Rodents-Montreal.ORG>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-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 7B0F57A18D
	for <gnats-bugs@www.NetBSD.org>; Thu, 23 Jan 2020 05:32:12 +0000 (UTC)
Message-Id: <202001230532.AAA23269@Stone.Rodents-Montreal.ORG>
Date: Thu, 23 Jan 2020 00:32:08 -0500 (EST)
From: Mouse <mouse@Rodents-Montreal.ORG>
Reply-To: mouse@Rodents-Montreal.ORG
To: gnats-bugs@www.NetBSD.org
Subject: fish(8) infinite loop
X-Send-Pr-Version: 3.95

>Number:         54885
>Category:       bin
>Synopsis:       fish(8) infinite-loops with EOF to the instructions? question
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 23 05:35:00 +0000 2020
>Closed-Date:    Sun Jul 25 02:05:40 +0000 2021
>Last-Modified:  Sun Jul 25 02:05:40 +0000 2021
>Originator:     Mouse
>Release:        NetBSD 8.0, 5.2, 4.0.1, and 1.4T
>Organization:
Dis-
>Environment:
System: NetBSD Stone.Rodents-Montreal.ORG 4.0.1 NetBSD 4.0.1 (GEN401) #0: Fri May 24 21:39:53 EDT 2019 mouse@Stone.Rodents-Montreal.ORG:/home/mouse/kbuild/GEN401 i386
Architecture: i386
Machine: i386
(The above are from the machine I'm running send-pr on.  I see this
issue on an 8.0 machine, a 5.2 machine, and a 1.4T machine as well, but
this is the one with mail working well on it.)
>Description:
	EOF to the "want instructions?" question makes fish(8)
	infinite-loop.  (Also, typing return without answering the
	question "does nothing"; you need a second return to proceed in
	that case.)
>How-To-Repeat:
	Start fish(8).  At the

	Would you like instructions (y or n)? 

	prompt, type your EOF character.  Watch fish infinite-loop.

	For the other issue, enter a zero-length line there.  Notice
	fish does not proceed until you give it _another_ newline.
>Fix:
	This works for me on one of my 5.2 machines:

diff --git a/games/fish/fish.c b/games/fish/fish.c
index becedf6..2ea86f8 100644
--- a/games/fish/fish.c
+++ b/games/fish/fish.c
@@ -440,7 +440,14 @@ instructions(void)

 	(void)printf("Would you like instructions (y or n)? ");
 	input = getchar();
-	while (getchar() != '\n');
+ if (input != '\n')
+  { while (1)
+     { int c;
+       c = getchar();
+       if (c == '\n') break;
+       if (c == EOF) exit(0);
+     }
+  }
 	if (input != 'y')
 		return;


>Release-Note:

>Audit-Trail:
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54885 CVS commit: src/games/fish
Date: Sun, 25 Jul 2021 02:00:43 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Sun Jul 25 02:00:42 UTC 2021

 Modified Files:
 	src/games/fish: fish.c

 Log Message:
 Flush input to EOL correctly in games/fish.

 PR 54885 from Mouse, with a somewhat different patch.


 To generate a diff of this commit:
 cvs rdiff -u -r1.26 -r1.27 src/games/fish/fish.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->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sun, 25 Jul 2021 02:05:40 +0000
State-Changed-Why:
fixed, thanks
(but we haven't yet restricted games to the super-user)


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.