From fujimoto@ns.kf.mnc.waseda.ac.jp  Fri Oct  9 01:49:17 1998
Received: from ns.kf.mnc.waseda.ac.jp (ns.kf.mnc.waseda.ac.jp [133.9.10.98])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id BAA23346
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 9 Oct 1998 01:49:17 -0700 (PDT)
          (envelope-from fujimoto@ns.kf.mnc.waseda.ac.jp)
Received: (from fujimoto@localhost)
	by ns.kf.mnc.waseda.ac.jp (8.8.8/3.6Wbeta5/970731) id RAA27839;
	Fri, 9 Oct 1998 17:49:10 +0900 (JST)
Message-Id: <199810090849.RAA27839@ns.kf.mnc.waseda.ac.jp>
Date: Fri, 9 Oct 1998 17:49:10 +0900 (JST)
From: fujimoto@oscar.elec.waseda.ac.jp
Reply-To: fujimoto@oscar.elec.waseda.ac.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject: /usr/bin/head -c never exit for short inputs
X-Send-Pr-Version: 3.2

>Number:         8225
>Category:       bin
>Synopsis:       /usr/bin/head -c never exit for short inputs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct  9 01:50:00 PDT 1998
>Closed-Date:    Fri Oct 9 03:40:20 PDT 1998
>Last-Modified:  Fri Oct  9 04:35:32 PDT 1998
>Originator:     FUJIMOTO Kensaku
>Release:        FreeBSD 2.2.7-RELEASE i386
>Organization:
Waseda University
>Environment:

FreeBSD /usr/bin/head with "-c" option has this bug.
FreeBSD 2.2.7-RELEASE and FreeBSD-current also contain it.

>Description:

"head -c <n>" never exit and loops forever (until it is killed),
if the input stream has fewer bytes than specified (n).

>How-To-Repeat:

echo abc | head -c 10

>Fix:
	
Please apply the patch below:

--- ../ORIG/head/head.c	Mon Sep 15 17:17:20 1997
+++ head.c	Fri Oct  9 17:10:04 1998
@@ -155,7 +155,7 @@
 		else
 			readlen = sizeof(buf);
 		readlen = fread(buf, sizeof(char), readlen, fp);
-		if (readlen == EOF)
+		if (readlen == 0)
 			break;
 		if (fwrite(buf, sizeof(char), readlen, stdout) != readlen)
 			err(1, "stdout");
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: des 
State-Changed-When: Fri Oct 9 03:40:20 PDT 1998 
State-Changed-Why:  
Fixed in revision 1.9 (current) and 1.3.2.4 (stable) of 
src/usr.bin/head/head.c , thanks! 
>Unformatted:
