From patchwork Thu Aug 8 19:40:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yann Droneaud X-Patchwork-Id: 2841362 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C52B29F271 for ; Thu, 8 Aug 2013 19:53:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8964C20375 for ; Thu, 8 Aug 2013 19:53:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FE632034A for ; Thu, 8 Aug 2013 19:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966208Ab3HHTxA (ORCPT ); Thu, 8 Aug 2013 15:53:00 -0400 Received: from smtp25.services.sfr.fr ([93.17.128.118]:3421 "EHLO smtp25.services.sfr.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966115Ab3HHTwz (ORCPT ); Thu, 8 Aug 2013 15:52:55 -0400 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2506.sfr.fr (SMTP Server) with ESMTP id 34B3F70000AB; Thu, 8 Aug 2013 21:42:47 +0200 (CEST) Received: from localhost.localdomain (187.20.90.92.rev.sfr.net [92.90.20.187]) by msfrf2506.sfr.fr (SMTP Server) with ESMTP id B584A70000A7; Thu, 8 Aug 2013 21:42:44 +0200 (CEST) X-SFR-UUID: 20130808194244743.B584A70000A7@msfrf2506.sfr.fr Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id r78JgMKv003063; Thu, 8 Aug 2013 21:42:23 +0200 Received: (from ydroneaud@localhost) by localhost.localdomain (8.14.7/8.14.7/Submit) id r78JgFix003062; Thu, 8 Aug 2013 21:42:15 +0200 From: Yann Droneaud To: linux-rdma@vger.kernel.org Cc: Yann Droneaud Subject: [PATCH libibverbs v2 04/11] read_config(): move file type check in read_config_file() Date: Thu, 8 Aug 2013 21:40:47 +0200 Message-Id: <22fb4f5dcc4e545dfcc9168429e50c11bd3611ab.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 Check the configuration file inside the function parsing it. Signed-off-by: Yann Droneaud --- src/init.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/init.c b/src/init.c index 34150b5..953ed9f 100644 --- a/src/init.c +++ b/src/init.c @@ -243,6 +243,19 @@ static void read_config_file(const char *path) char *field; size_t buflen = 0; ssize_t len; + struct stat buf; + + if (stat(path, &buf)) { + fprintf(stderr, PFX "Warning: couldn't stat config file '%s'.\n", + path); + return; + } + + if (!S_ISREG(buf.st_mode)) { + fprintf(stderr, PFX "Warning: invalid config file '%s'.\n", + path); + return; + } conf = fopen(path, "r" STREAM_CLOEXEC); if (!conf) { @@ -314,7 +327,6 @@ static void read_config(void) } while ((dent = readdir(conf_dir))) { - struct stat buf; if (dent->d_name[0] == '.') continue; @@ -328,17 +340,8 @@ static void read_config(void) goto out; } - if (stat(path, &buf)) { - fprintf(stderr, PFX "Warning: couldn't stat config file '%s'.\n", - path); - goto next; - } - - if (!S_ISREG(buf.st_mode)) - goto next; - read_config_file(path); -next: + free(path); }