Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Oct 1998 17:49:10 +0900 (JST)
From:      fujimoto@oscar.elec.waseda.ac.jp
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/8225: /usr/bin/head -c never exit for short inputs
Message-ID:  <199810090849.RAA27839@ns.kf.mnc.waseda.ac.jp>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct  9 01:50:00 PDT 1998
>Last-Modified:
>Originator:     FUJIMOTO Kensaku
>Organization:
Waseda University
>Release:        FreeBSD 2.2.7-RELEASE i386
>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");
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810090849.RAA27839>