From patchwork Thu Aug 8 19:40:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Droneaud X-Patchwork-Id: 2841366 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 806ABBF546 for ; Thu, 8 Aug 2013 19:53:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 646172034E for ; Thu, 8 Aug 2013 19:53:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F7192034A for ; Thu, 8 Aug 2013 19:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966063Ab3HHTxD (ORCPT ); Thu, 8 Aug 2013 15:53:03 -0400 Received: from smtp23.services.sfr.fr ([93.17.128.22]:13313 "EHLO smtp23.services.sfr.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966044Ab3HHTwz (ORCPT ); Thu, 8 Aug 2013 15:52:55 -0400 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2316.sfr.fr (SMTP Server) with ESMTP id C73B87000050; Thu, 8 Aug 2013 21:42:56 +0200 (CEST) Received: from localhost.localdomain (187.20.90.92.rev.sfr.net [92.90.20.187]) by msfrf2316.sfr.fr (SMTP Server) with ESMTP id 6877F70000B6; Thu, 8 Aug 2013 21:42:56 +0200 (CEST) X-SFR-UUID: 20130808194256427.6877F70000B6@msfrf2316.sfr.fr Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id r78JgstQ003079; Thu, 8 Aug 2013 21:42:55 +0200 Received: (from ydroneaud@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id r78Jgmgu003078; Thu, 8 Aug 2013 21:42:48 +0200 From: Yann Droneaud To: linux-rdma@vger.kernel.org Cc: Yann Droneaud Subject: [PATCH libibverbs v2 08/11] read_config(): refuse to open IBV_CONFIG_DIR if it's not a directory Date: Thu, 8 Aug 2013 21:40:51 +0200 Message-Id: <64fd9c35244a9d3ed56f77b049accb00b9ec95e9.1375952089.git.ydroneaud@opteya.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP O_DIRECTORY is an option to open() to ensure the given path is a directory. If IBV_CONFIG_DIR path is not pointing to a directory, open() will failed. Note: if IBV_CONFIG_DIR is a symlink, it will be followed. O_DIRECTORY doesn't disable path resolution. See open()[1][2] for more information. Links: - [1] open - [2] open(2) Signed-off-by: Yann Droneaud --- configure.ac | 6 ++++++ src/init.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b8d4cea..9544726 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,12 @@ AC_CHECK_HEADERS([fcntl.h sys/socket.h]) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST +AC_CHECK_DECLS([O_DIRECTORY],,[AC_DEFINE([O_DIRECTORY],[0], [Defined to 0 if not provided])], +[[ +#ifdef HAVE_FCNTL_H +# include +#endif +]]) AC_CHECK_DECLS([O_CLOEXEC],,[AC_DEFINE([O_CLOEXEC],[0], [Defined to 0 if not provided])], [[ #ifdef HAVE_FCNTL_H diff --git a/src/init.c b/src/init.c index 0e3cdf0..c2e7bfb 100644 --- a/src/init.c +++ b/src/init.c @@ -325,7 +325,7 @@ static void read_config(void) struct dirent *dent; struct stat buf; - conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_CLOEXEC); + conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC); if (conf_dirfd == -1) { fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n", IBV_CONFIG_DIR);