[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1wBkx9_XW-HXkfNXoK7gpBCW42byzidUd3ZO54Rnh74-sTkNu3jQVEvSFiyDc4WE6vzjMu92sAmAaasF2rj7olsWwQ50wzrGwyx6l6kAlqs=@protonmail.ch>
Date: Sun, 12 Aug 2018 19:47:15 +0000
From: ykp@...tonmail.ch
To: "linux-ext4@...r.kernel.org" <linux-ext4@...r.kernel.org>
Subject: [PATCH] ext2/e2fsprogs: fix cppcheck warnings
>From bbcbf9936c739e53327a9bee4790a167f34fc04a Mon Sep 17 00:00:00 2001
From: Vladyslav Tsilytskyi <ykp@...tonmail.ch>
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 <ykp@...tonmail.ch>
---
intl/localealias.c | 10 ++++++++--
lib/ext2fs/dosio.c | 9 ++++++---
lib/ext2fs/tdb.c | 3 +--
3 files changed, 15 insertions(+), 7 deletions(-)
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) {
--
2.17.1
Powered by blists - more mailing lists