misc/96191: "cat" can display directory contents

Bjoern Voigt bjoern at cs.tu-berlin.de
Sun Apr 23 10:20:18 UTC 2006

The following reply was made to PR misc/96191; it has been noted by GNATS.

From: Bjoern Voigt <bjoern at cs.tu-berlin.de>
To: bug-followup at FreeBSD.org
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 
 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:
     $ echo $0; head < /etc
      echo $0; head < /etc
     head: error reading `standard input': Is a directory

More information about the freebsd-bugs mailing list