From nobody@FreeBSD.org  Sun Apr 23 08:50:32 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E3E1216A406
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 23 Apr 2006 08:50:32 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id AA1C943D48
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 23 Apr 2006 08:50:32 +0000 (GMT)
	(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 k3N8oWMb066808
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 23 Apr 2006 08:50:32 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k3N8oWre066807;
	Sun, 23 Apr 2006 08:50:32 GMT
	(envelope-from nobody)
Message-Id: <200604230850.k3N8oWre066807@www.freebsd.org>
Date: Sun, 23 Apr 2006 08:50:32 GMT
From: Bjoern Voigt <bjoern@cs.tu-berlin.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: "cat" can display directory contents
X-Send-Pr-Version: www-2.3

>Number:         96191
>Category:       misc
>Synopsis:       "cat" can display directory contents
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Apr 23 09:00:29 GMT 2006
>Closed-Date:    Sun Apr 23 09:13:08 GMT 2006
>Last-Modified:  Mon Apr 24 14:10:19 GMT 2006
>Originator:     Bjoern Voigt
>Release:        6.1-PRERELEASE
>Organization:
>Environment:
FreeBSD my.host.name 6.1-PRERELEASE FreeBSD 6.1-PRERELEASE #0: Mon Mar 27 18:26:36 CEST 2006     root@chemnitz.dialup.cs.tu-berlin.de:/usr/src/sys/GENERIC.my  i386


>Description:
The FreeBSD's version of "cat" is able to display directory contains:

$ cat /etc
(garbage)

Solaris (tested with SunOS 5.9) shows the same behavior.

The behavior on directories in not described in the manual page. 

>How-To-Repeat:
$ cat /etc
>Fix:
"cat" from "coreutils" (GNU Linux) refuses to display directory contents.

$ cat /etc
cat: /etc: Is a directory


>Release-Note:
>Audit-Trail:

From: "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To: Bjoern Voigt <bjoern@cs.tu-berlin.de>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/96191: "cat" can display directory contents 
Date: Sun, 23 Apr 2006 11:05:13 +0200

 In message <200604230850.k3N8oWre066807@www.freebsd.org>, Bjoern Voigt writes:
 
 >The FreeBSD's version of "cat" is able to display directory contains:
 >
 >$ cat /etc
 >(garbage)
 
 In UNIX a file is a file is a file.
 
 But also, directories, pipes and devices are files.
 
 And as such cat(1) works on them, as it should.
 
 This is not a bug.
 
 -- 
 Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
 phk@FreeBSD.ORG         | TCP/IP since RFC 956
 FreeBSD committer       | BSD since 4.3-tahoe    
 Never attribute to malice what can adequately be explained by incompetence.
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Sun Apr 23 09:12:31 UTC 2006 
State-Changed-Why:  
As Poul explains this is not a bug. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=96191 

From: Bjoern Voigt <bjoern@cs.tu-berlin.de>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/96191: "cat" can display directory contents
Date: Sun, 23 Apr 2006 12:12:46 +0200

 I know, that everything is a file on UNIX. But also a system should 
 prevent a user from falling into a trap. Shell script authors can fall 
 into a trap if they accidentally work on directories with "cat" and 
 "cat" returns with exit code 0. I think the Linux' implementation is 
 better here, but this is my personal opinion.
 
 I looked at the problem more detailed now. I found, that the different 
 behavior between "cat /etc" on FreeBSD and Linux does not come from the 
 cat-tools itself. The difference comes from different implementations of 
 the read(2) system call. Linux's read(2) call refuses to read from 
 directories.
 
 I tested FreeBSD's "cat" on Linux:
 
     * Linux has no support for 'udom' and does not know the __FBSDID
       macro (both is not important here)
     * compilation on Linux: gcc -g -o cat2 -DNO_UDOM_SUPPORT
       -D'__FBSDID(a)=/**/' cat.c
     * The result:
       $ ./cat2 /etc
       cat2: /etc: Is a directory
 
 As a result also other UNIX tools behave different on Linux and on 
 FreeBSD. For instance the same version of "bash" behaves different on 
 Linux and on FreeBSD:
 
     FreeBSD:
     $ echo $0; head < /etc
     /usr/local/bin/bash
     (garbage)
 
     Linux:
      echo $0; head < /etc
     -bash
     head: error reading `standard input': Is a directory
 
 
 
 

From: Parv <parv@pair.com>
To: Bjoern Voigt <bjoern@cs.tu-berlin.de>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/96191: "cat" can display directory contents
Date: Mon, 24 Apr 2006 10:05:23 -0400

 in message <200604230850.k3N8oWre066807@www.freebsd.org>,
 wrote Bjoern Voigt thusly...
 >
 > >Description:
 > The FreeBSD's version of "cat" is able to display directory contains:
 > 
 > $ cat /etc
 > (garbage)
 > 
 > Solaris (tested with SunOS 5.9) shows the same behavior.
 > 
 > The behavior on directories in not described in the manual page. 
 > 
 > >How-To-Repeat:
 > $ cat /etc
 
 I personally like this feature.
 
 BTW, a user can edit the directory entries too, at least in vi
 included w/ FreeBSD.
 
 
 > >Fix:
 > "cat" from "coreutils" (GNU Linux) refuses to display directory contents.
 > 
 > $ cat /etc
 > cat: /etc: Is a directory
 
 As a user i oppose the proposed change, regardless of the weight of my
 opinion.
 
 
   - Parv
 
 -- 
 
>Unformatted:
