From owner-freebsd-bugs Mon Jun 26 17:50: 8 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 239A537BA62 for ; Mon, 26 Jun 2000 17:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id RAA43193; Mon, 26 Jun 2000 17:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from teapot.egroups.net (teapot.egroups.net [63.204.207.250]) by hub.freebsd.org (Postfix) with SMTP id 1471737B69B for ; Mon, 26 Jun 2000 17:47:32 -0700 (PDT) (envelope-from kbyanc@teapot.egroups.com) Received: (qmail 17300 invoked from network); 27 Jun 2000 00:47:31 -0000 Received: (QMFILT: 1.0); 27 Jun 2000 01:47:31 -0000 Received: from dhcp147.corp.onelist.com (HELO kbyanc.corp.ONElist.com) (192.168.10.147) by teapot.egroups.net with SMTP; 27 Jun 2000 00:47:31 -0000 Received: (from kbyanc@localhost) by kbyanc.corp.ONElist.com (8.9.3/8.9.3) id RAA23860; Mon, 26 Jun 2000 17:47:31 -0700 (PDT) (envelope-from kbyanc@teapot.egroups.com) Message-Id: <200006270047.RAA23860@kbyanc.corp.ONElist.com> Date: Mon, 26 Jun 2000 17:47:31 -0700 (PDT) From: kbyanc@posi.net Reply-To: kbyanc@posi.net To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/19536: patch to prevent head'ing directories Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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 #include #include @@ -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