From owner-freebsd-bugs@FreeBSD.ORG Mon Apr 16 18:00:09 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A74E416A404 for ; Mon, 16 Apr 2007 18:00:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 83C6E13C46C for ; Mon, 16 Apr 2007 18:00:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l3GI08qk077851 for ; Mon, 16 Apr 2007 18:00:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l3GI08ta077850; Mon, 16 Apr 2007 18:00:08 GMT (envelope-from gnats) Resent-Date: Mon, 16 Apr 2007 18:00:08 GMT Resent-Message-Id: <200704161800.l3GI08ta077850@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ricardo Nabinger Sanchez Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 730FC16A400 for ; Mon, 16 Apr 2007 17:55:26 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [69.147.83.33]) by mx1.freebsd.org (Postfix) with ESMTP id 6256813C46C for ; Mon, 16 Apr 2007 17:55:26 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l3GHtQam052753 for ; Mon, 16 Apr 2007 17:55:26 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id l3GHoPvi047606; Mon, 16 Apr 2007 17:50:25 GMT (envelope-from nobody) Message-Id: <200704161750.l3GHoPvi047606@www.freebsd.org> Date: Mon, 16 Apr 2007 17:50:25 GMT From: Ricardo Nabinger Sanchez To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: bin/111711: cat(1) misbehaves with directories as parameters X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2007 18:00:09 -0000 >Number: 111711 >Category: bin >Synopsis: cat(1) misbehaves with directories as parameters >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: Mon Apr 16 18:00:08 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Ricardo Nabinger Sanchez >Release: 6.1 RELEASE >Organization: >Environment: FreeBSD sauron.lan.box 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Sun May 7 04:32:43 UTC 2006 root@opus.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 >Description: If a directory is passed to cat, it outputs its contents, (sometimes) mangles the terminal, and may misbehave, like in the second run with ". Makefile" as parameters. rnsanchez@sauron:~...src/usr.bin/cat% cat -n Makefile . 1 # @(#)Makefile 8.1 (Berkeley) 5/31/93 2 # $FreeBSD: src/bin/cat/Makefile,v 1.7 2001/12/04 01:57:37 obrien Exp $ 3 4 PROG= cat 5 6 .include 1 !g .cat.1.gzÙåø.Øö/~...src/usr.bin/cat% cat -n . Makefile 1 !g .cat.1.gzÙåø.Øö/~...src/usr.bin/cat% The patch supplied fixes this behavior, adding a check to skip directories: rnsanchez@sauron:~...src/usr.bin/cat% ./cat -n Makefile . 1 # @(#)Makefile 8.1 (Berkeley) 5/31/93 2 # $FreeBSD: src/bin/cat/Makefile,v 1.7 2001/12/04 01:57:37 obrien Exp $ 3 4 PROG= cat 5 6 .include rnsanchez@sauron:~...src/usr.bin/cat% ./cat -n . Makefile 1 # @(#)Makefile 8.1 (Berkeley) 5/31/93 2 # $FreeBSD: src/bin/cat/Makefile,v 1.7 2001/12/04 01:57:37 obrien Exp $ 3 4 PROG= cat 5 6 .include rnsanchez@sauron:~...src/usr.bin/cat% >How-To-Repeat: Just cat(1) a directory. >Fix: Diff against -CURRENT sources attached. Works OK on a 6.1-RELEASE. Patch attached with submission follows: Index: usr.bin/cat/cat.c =================================================================== RCS file: /home/ncvs/src/bin/cat/cat.c,v retrieving revision 1.32 diff -u -p -r1.32 cat.c --- usr.bin/cat/cat.c 10 Jan 2005 08:39:20 -0000 1.32 +++ usr.bin/cat/cat.c 16 Apr 2007 17:32:00 -0000 @@ -136,6 +136,7 @@ scanfiles(char *argv[], int cooked) int i = 0; char *path; FILE *fp; + struct stat sbuf; while ((path = argv[i]) != NULL || i == 0) { int fd; @@ -145,6 +146,19 @@ scanfiles(char *argv[], int cooked) fd = STDIN_FILENO; } else { filename = path; + /* + * Check if path refers to a directory, in which case + * it should not be opened. + */ + if (stat(path, &sbuf)) + err(1, "%s", filename); + if (S_ISDIR(sbuf.st_mode)) { + /* + * Silently skip this directory. + */ + ++i; + continue; + } fd = open(path, O_RDONLY); #ifndef NO_UDOM_SUPPORT if (fd < 0 && errno == EOPNOTSUPP) >Release-Note: >Audit-Trail: >Unformatted: