Subject: bin/33396: Global Warming may be caused by mv(1)
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 04/30/2006 22:25:00
>Number:         33396
>Category:       bin
>Synopsis:       Global Warming may be caused by mv(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 30 22:25:00 +0000 2006
>Originator:     Christian Biere
>Release:        NetBSD 3.99.18
>Environment:
System: NetBSD cyclonus 3.99.18 NetBSD 3.99.18 (STARSCREAM) #0: Mon Apr 24 06:03:27 CEST 2006 bin@cyclonus:/o/NetBSD/obj/sys/arch/i386/compile/STARSCREAM i386
Architecture: i386
Machine: i386
>Description:
When mv(1) is used in interactive mode (-i), it fails to check for
EOF on stdin after reading the first input character waiting for
the line termination. This can cause a busy loop which terminates
only when the process dies.

>How-To-Repeat:

$ printf 'Yes, please!'|mv -i /dev/null /etc/passwd

>Fix:

Index: mv.c
===================================================================
RCS file: /cvsroot/src/bin/mv/mv.c,v
retrieving revision 1.35
diff -u -p -r1.35 mv.c
--- mv.c	3 Jun 2005 13:55:04 -0000	1.35
+++ mv.c	30 Apr 2006 22:10:38 -0000
@@ -189,8 +189,11 @@ do_move(char *from, char *to)
 		} else
 			ask = 0;
 		if (ask) {
-			if ((ch = getchar()) != EOF && ch != '\n')
-				while (getchar() != '\n');
+			if ((ch = getchar()) != EOF && ch != '\n') {
+				int ch2;
+				while ((ch2 = getchar()) != EOF && ch2 != '\n')
+					continue;
+			}
 			if (ch != 'y' && ch != 'Y')
 				return (0);
 		}