From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 2 04:40:03 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EC9721065678 for ; Tue, 2 Mar 2010 04:40:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B031F8FC18 for ; Tue, 2 Mar 2010 04:40:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id o224e2R0019403 for ; Tue, 2 Mar 2010 04:40:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id o224e28h019402; Tue, 2 Mar 2010 04:40:02 GMT (envelope-from gnats) Resent-Date: Tue, 2 Mar 2010 04:40:02 GMT Resent-Message-Id: <201003020440.o224e28h019402@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, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 59B881065690 for ; Tue, 2 Mar 2010 04:32:00 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 30B838FC32 for ; Tue, 2 Mar 2010 04:32:00 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o224W0RR008730 for ; Tue, 2 Mar 2010 04:32:00 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o224VxH1008729; Tue, 2 Mar 2010 04:31:59 GMT (envelope-from nobody) Message-Id: <201003020431.o224VxH1008729@www.freebsd.org> Date: Tue, 2 Mar 2010 04:31:59 GMT From: Garrett Cooper To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/144411: mtree(8) doesn't reject non-regular files for -X 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: Tue, 02 Mar 2010 04:40:03 -0000 >Number: 144411 >Category: bin >Synopsis: mtree(8) doesn't reject non-regular files for -X >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Mar 02 04:40:02 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Garrett Cooper >Release: RELENG_8 >Organization: Cisco Systems, Inc >Environment: FreeBSD garrcoop-fbsd.cisco.com 8.0-STABLE FreeBSD 8.0-STABLE #2: Wed Feb 3 16:57:07 PST 2010 garrcoop@garrcoop-fbsd.cisco.com:/usr/obj/usr/src/sys/LAPPY_X86 i386 >Description: Didn't fully read the manpage for mtree(8), and I assumed that -X accepted exclusion arguments like tar does. Turns out that wasn't the case, and mtree hangs when given directories via -X: [root@garrcoop-fbsd /usr/home/garrcoop/head/tools/regression/lib/libc/gen]# mtree -X /boot/ ^C The patch attached does a stat(2) on the file first to ensure that the resolved file is in fact legitimate, then proceeds to poke at the file to make sure that it's a regular file. This is a draft patch and can and will be revised if necessary.. >How-To-Repeat: mtree -X /boot >Fix: See proposed patch attached. Patch attached with submission follows: Index: excludes.c =================================================================== --- excludes.c (revision 204532) +++ excludes.c (working copy) @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include /* XXX for mtree.h */ #include @@ -39,6 +40,7 @@ #include #include #include +#include #include "mtree.h" /* XXX for extern.h */ #include "extern.h" @@ -66,10 +68,23 @@ FILE *fp; char *line, *str; struct exclude *e; + struct stat exclude_stat; size_t len; + /* Let's resolve the name via stat(2) so symlinks to files pass. */ + if (stat(name, &exclude_stat) < 0) { + err(1, "%s", name); + } + /* Don't let certain files like directories, fifos, etc pass. */ + if (!S_ISREG(exclude_stat.st_mode)) { + /* Make the error message make sense for the directory error + * case. All other values can be EINVAL. */ + errno = S_ISDIR(exclude_stat.st_mode) ? EISDIR : EINVAL; + err(1, "%s", name); + } + fp = fopen(name, "r"); - if (fp == 0) + if (fp == NULL) err(1, "%s", name); while ((line = fgetln(fp, &len)) != 0) { >Release-Note: >Audit-Trail: >Unformatted: