From owner-freebsd-bugs@FreeBSD.ORG Sun Apr 23 10:20:18 2006 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 [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2836516A401 for ; Sun, 23 Apr 2006 10:20:18 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id BEBEC43D46 for ; Sun, 23 Apr 2006 10:20:17 +0000 (GMT) (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 k3NAKFpn042101 for ; Sun, 23 Apr 2006 10:20:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k3NAKF1Q042100; Sun, 23 Apr 2006 10:20:15 GMT (envelope-from gnats) Date: Sun, 23 Apr 2006 10:20:15 GMT Message-Id: <200604231020.k3NAKF1Q042100@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bjoern Voigt Cc: Subject: Re: misc/96191: "cat" can display directory contents X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Bjoern Voigt List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Apr 2006 10:20:18 -0000 The following reply was made to PR misc/96191; it has been noted by GNATS. From: Bjoern Voigt 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