Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jun 2000 22:40:04 -0700 (PDT)
From:      Kelly Yancey <kbyanc@posi.net>
To:        freebsd-bugs@FreeBSD.org
Subject:   subject=Re: bin/19536: patch to prevent head'ing directories
Message-ID:  <200006270540.WAA84100@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/19536; it has been noted by GNATS.

From: Kelly Yancey <kbyanc@posi.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: subject=Re: bin/19536: patch to prevent head'ing directories
Date: Mon, 26 Jun 2000 22:34:47 -0700 (PDT)

   Attached is a more correct patch, please apply it instead. Thanks,
 
   Kelly
 
 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 05:25:44
 @@ -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 (S_ISDIR(sb.st_mode))
 +				errx(1, "%s is a directory", *argv);
 +			if (S_ISLNK(sb.st_mode))
 +				/* This should transparently be resolved and
 +				 * thus never happen.
 +				 */
 +				errx(1, "%s is a symlink", *argv);
 +			if (S_ISWHT(sb.st_mode))
 +				/* This should never happen. */
 +				errx(1, "%s is a whiteout entry", *argv);
  			if (argc > 1) {
  				(void)printf("%s==> %s <==\n",
  				    first ? "" : "\n", *argv);
 
 


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?200006270540.WAA84100>