From patchwork Thu Aug 8 19:40:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Droneaud X-Patchwork-Id: 2841359 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 5E676BF546 for ; Thu, 8 Aug 2013 19:53:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27F9D2034A for ; Thu, 8 Aug 2013 19:53:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E241720362 for ; Thu, 8 Aug 2013 19:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966256Ab3HHTw5 (ORCPT ); Thu, 8 Aug 2013 15:52:57 -0400 Received: from smtp21.services.sfr.fr ([93.17.128.1]:49556 "EHLO smtp21.services.sfr.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966226Ab3HHTw4 (ORCPT ); Thu, 8 Aug 2013 15:52:56 -0400 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2106.sfr.fr (SMTP Server) with ESMTP id 83FB87000082; Thu, 8 Aug 2013 21:42:51 +0200 (CEST) Received: from localhost.localdomain (187.20.90.92.rev.sfr.net [92.90.20.187]) by msfrf2106.sfr.fr (SMTP Server) with ESMTP id 6335A700005D; Thu, 8 Aug 2013 21:42:49 +0200 (CEST) X-SFR-UUID: 20130808194249406.6335A700005D@msfrf2106.sfr.fr Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id r78JglgR003075; Thu, 8 Aug 2013 21:42:48 +0200 Received: (from ydroneaud@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id r78JglnV003074; Thu, 8 Aug 2013 21:42:47 +0200 From: Yann Droneaud To: linux-rdma@vger.kernel.org Cc: Yann Droneaud Subject: [PATCH libibverbs v2 07/11] read_config(): check opened directory Date: Thu, 8 Aug 2013 21:40:50 +0200 Message-Id: <056f86d1d21882e330c4035a8c5618e1d4fea381.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 After opening the directory, call fstat() on directory file descriptor so that its parameters can be checked later. Signed-off-by: Yann Droneaud --- src/init.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/init.c b/src/init.c index 150adcf..0e3cdf0 100644 --- a/src/init.c +++ b/src/init.c @@ -323,6 +323,7 @@ static void read_config(void) int conf_dirfd; DIR *conf_dir; struct dirent *dent; + struct stat buf; conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_CLOEXEC); if (conf_dirfd == -1) { @@ -331,12 +332,23 @@ static void read_config(void) return; } + if (fstat(conf_dirfd, &buf)) { + fprintf(stderr, PFX "Warning: couldn't stat config directory '%s'.\n", + IBV_CONFIG_DIR); + goto out; + } + + if (!S_ISDIR(buf.st_mode)) { + fprintf(stderr, PFX "Warning: invalid config directory '%s'.\n", + IBV_CONFIG_DIR); + goto out; + } + conf_dir = fdopendir(conf_dirfd); if (!conf_dir) { fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n", IBV_CONFIG_DIR); - close(conf_dirfd); - return; + goto out; } while ((dent = readdir(conf_dir))) { @@ -351,6 +363,11 @@ static void read_config(void) } closedir(conf_dir); + + return; + +out: + close(conf_dirfd); } static struct ibv_device *try_driver(struct ibv_driver *driver,