From owner-svn-src-head@FreeBSD.ORG Tue Jun 10 06:04:26 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 12D88619; Tue, 10 Jun 2014 06:04:26 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 009AC2C63; Tue, 10 Jun 2014 06:04:26 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5A64PeD088036; Tue, 10 Jun 2014 06:04:25 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5A64PSD088035; Tue, 10 Jun 2014 06:04:25 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <201406100604.s5A64PSD088035@svn.freebsd.org> From: Rui Paulo Date: Tue, 10 Jun 2014 06:04:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267317 - head/usr.bin/dtc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jun 2014 06:04:26 -0000 Author: rpaulo Date: Tue Jun 10 06:04:25 2014 New Revision: 267317 URL: http://svnweb.freebsd.org/changeset/base/267317 Log: dtc: don't crash if the argument is a directory. Modified: head/usr.bin/dtc/fdt.cc Modified: head/usr.bin/dtc/fdt.cc ============================================================================== --- head/usr.bin/dtc/fdt.cc Tue Jun 10 05:58:46 2014 (r267316) +++ head/usr.bin/dtc/fdt.cc Tue Jun 10 06:04:25 2014 (r267317) @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include "dtb.hh" namespace dtc @@ -1078,6 +1080,13 @@ device_tree::buffer_for_file(const char fprintf(stderr, "Unable to open file %s\n", path); return 0; } + struct stat st; + if (fstat(source, &st) == 0 && S_ISDIR(st.st_mode)) + { + fprintf(stderr, "File %s is a directory\n", path); + close(source); + return 0; + } input_buffer *b = new mmap_input_buffer(source); // Keep the buffer that owns the memory around for the lifetime // of this FDT. Ones simply referring to it may have shorter