From patchwork Sun Aug 12 19:47:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ykp@protonmail.ch X-Patchwork-Id: 956733 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.ch Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=protonmail.ch header.i=@protonmail.ch header.b="bvMUi0NO"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41pW0y2Ggdz9s9l for ; Mon, 13 Aug 2018 06:38:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728009AbeHLW02 (ORCPT ); Sun, 12 Aug 2018 18:26:28 -0400 Received: from mail-40133.protonmail.ch ([185.70.40.133]:44944 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbeHLW02 (ORCPT ); Sun, 12 Aug 2018 18:26:28 -0400 Date: Sun, 12 Aug 2018 19:47:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.ch; s=default; t=1534103238; bh=eOiis3uEt2lTXGf5yAVAoEpj2A8/OHDFTFFYjHJ1888=; h=Date:To:From:Reply-To:Subject:Feedback-ID:From; b=bvMUi0NO1RaENUQ0tMDN8okyczSAOPRjEamZmmugC8Z/CiLcUKUanSQGH7GvPCq/f mjIRty6VT0/jXlu/1nsG8O/nYNYMPHSBg0wIWyKjyQkF2bug5K/Vua63hyxwVniuzN v9xVpqrlGaJUdHXwdJ8DR/yCnilBx1XARHnlp6R8= To: "linux-ext4@vger.kernel.org" From: ykp@protonmail.ch Reply-To: ykp@protonmail.ch Subject: [PATCH] ext2/e2fsprogs: fix cppcheck warnings Message-ID: <1wBkx9_XW-HXkfNXoK7gpBCW42byzidUd3ZO54Rnh74-sTkNu3jQVEvSFiyDc4WE6vzjMu92sAmAaasF2rj7olsWwQ50wzrGwyx6l6kAlqs=@protonmail.ch> Feedback-ID: YAgkuq_oFuNPZqxe61TkSEEen06gSt05I78Z79qvyG2Rdsm-uZo1DGGDUO9XCP-fqPZVfvE-4ddLwh9yNWy3_Q==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.1 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.protonmail.ch Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From bbcbf9936c739e53327a9bee4790a167f34fc04a Mon Sep 17 00:00:00 2001 From: Vladyslav Tsilytskyi Date: Sun, 12 Aug 2018 21:34:42 +0200 Subject: [PATCH] Fix static analysis warnings. Prevented file descriptor leaks in localealias.c "!length" code in tdb.c didn't make any sense because variable was uninitialized. Swapped blocks in dosio.c to prevent "part" variable leak if any return from previous block executed. Signed-off-by: Vladyslav Tsilytskyi --- intl/localealias.c | 10 ++++++++-- lib/ext2fs/dosio.c | 9 ++++++--- lib/ext2fs/tdb.c | 3 +-- 3 files changed, 15 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/intl/localealias.c b/intl/localealias.c index 7a092a0d..443a6b38 100644 --- a/intl/localealias.c +++ b/intl/localealias.c @@ -300,7 +300,10 @@ read_alias_file (const char *fname, int fname_len) if (nmap >= maxmap) if (__builtin_expect (extend_alias_table (), 0)) - return added; + { + fclose (fp); + return added; + } alias_len = strlen (alias) + 1; value_len = strlen (value) + 1; @@ -313,7 +316,10 @@ read_alias_file (const char *fname, int fname_len) ? alias_len + value_len : 1024)); char *new_pool = (char *) realloc (string_space, new_size); if (new_pool == NULL) - return added; + { + fclose (fp); + return added; + } if (__builtin_expect (string_space != new_pool, 0)) { diff --git a/lib/ext2fs/dosio.c b/lib/ext2fs/dosio.c index d0cf2690..0f107631 100644 --- a/lib/ext2fs/dosio.c +++ b/lib/ext2fs/dosio.c @@ -212,9 +212,6 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel) * Check whether the partition data is already in cache */ - part = (PARTITION*)malloc(sizeof(PARTITION)); - if (!part) - return ENOMEM; { int i = 0; @@ -230,6 +227,10 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel) } } + part = (PARTITION*)malloc(sizeof(PARTITION)); + if (!part) + return ENOMEM; + /* * Drive number & optionally partn number */ @@ -257,6 +258,7 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel) default: _dio_error = ERR_BADDEV; + free(part); return ENODEV; } @@ -264,6 +266,7 @@ static errcode_t dos_open(const char *dev, int flags, io_channel *channel) { /* We don't support floppies for now */ _dio_error = ERR_NOTSUPP; + free(part); return EINVAL; } diff --git a/lib/ext2fs/tdb.c b/lib/ext2fs/tdb.c index 195a4c0b..9f78e447 100644 --- a/lib/ext2fs/tdb.c +++ b/lib/ext2fs/tdb.c @@ -82,8 +82,7 @@ static char *rep_strdup(const char *s) if (!s) return NULL; - if (!length) - length = strlen(s); + length = strlen(s); ret = malloc(length + 1); if (ret) {