Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jun 2000 17:47:31 -0700 (PDT)
From:      kbyanc@posi.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/19536: patch to prevent head'ing directories
Message-ID:  <200006270047.RAA23860@kbyanc.corp.ONElist.com>

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

>Number:         19536
>Category:       bin
>Synopsis:       patch to prevent head'ing directories
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 26 17:50:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Kelly Yancey
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
>Environment:

FreeBSD backroom.corp.ONElist.com 5.0-CURRENT FreeBSD 5.0-CURRENT #3: Sat
Jun 10 12:08:26 PDT 2000
kbyanc@backroom.corp.ONElist.com:/usr/src/sys/compile/BACKROOM  i386

>Description:

	Similar to my previous PR (19514), except this patch affects
	head(1) rather than tail(1). Otherwise it is identical. This patch
	is made again -current head.c.

>How-To-Repeat:

	head .

>Fix:

Index: usr.bin/head/head.c
===================================================================
RCS file: /home/cvs/src/usr.bin/head/head.c,v
retrieving revision 1.10
diff -u -r1.10 head.c
--- usr.bin/head/head.c	1999/08/28 01:01:58	1.10
+++ usr.bin/head/head.c	2000/06/27 00:40:28
@@ -45,6 +45,7 @@
   "$FreeBSD: src/usr.bin/head/head.c,v 1.10 1999/08/28 01:01:58 peter Exp $";
 #endif /* not lint */
 
+#include <sys/stat.h>
 #include <sys/types.h>
 
 #include <ctype.h>
@@ -73,6 +74,7 @@
 	char *argv[];
 {
 	register int ch;
+	struct stat sb;
 	FILE *fp;
 	int first, linecnt = -1, bytecnt = -1;
 	char *ep;
@@ -103,11 +105,22 @@
 		linecnt = 10;
 	if (*argv) {
 		for (first = 1; *argv; ++argv) {
-			if ((fp = fopen(*argv, "r")) == NULL) {
+			if ((fp = fopen(*argv, "r")) == NULL ||
+			    fstat(fileno(fp), &sb)) {
 				warn("%s", *argv);
 				eval = 1;
 				continue;
 			}
+			if (sb.st_mode & S_IFDIR)
+				errx(1, "%s is a directory", *argv);
+			if (sb.st_mode & S_IFLNK)
+				/* This should transparently be resolved and
+				 * thus never happen.
+				 */
+				errx(1, "%s is a symlink", *argv);
+			if (sb.st_mode & S_IFWHT)
+				/* This should never happen. */
+				errx(1, "%s is a whiteout entry", *argv);
 			if (argc > 1) {
 				(void)printf("%s==> %s <==\n",
 				    first ? "" : "\n", *argv);

>Release-Note:
>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?200006270047.RAA23860>