linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: linux-ext4@vger.kernel.org
Subject: [PATCH 2/2] e2fsprogs: fix potential memory leak in path_append()
Date: Tue, 15 Jan 2019 14:42:03 +0100	[thread overview]
Message-ID: <20190115134203.11448-2-lczerner@redhat.com> (raw)
In-Reply-To: <20190115134203.11448-1-lczerner@redhat.com>

If realloc() fails in path_append() we will lose a memory pointed to by
target->path. Fix it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 misc/create_inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/misc/create_inode.c b/misc/create_inode.c
index 05aa6363..cedbba52 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -704,10 +704,12 @@ struct file_info {
 static errcode_t path_append(struct file_info *target, const char *file)
 {
 	if (strlen(file) + target->path_len + 1 > target->path_max_len) {
+		void *p;
 		target->path_max_len *= 2;
-		target->path = realloc(target->path, target->path_max_len);
-		if (!target->path)
+		p = realloc(target->path, target->path_max_len);
+		if (p == NULL)
 			return EXT2_ET_NO_MEMORY;
+		target->path = p;
 	}
 	target->path_len += sprintf(target->path + target->path_len, "/%s",
 				    file);
-- 
2.20.1

  reply	other threads:[~2019-01-15 13:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 13:42 [PATCH 1/2] e2freefrag: fix memory leak in scan_online() Lukas Czerner
2019-01-15 13:42 ` Lukas Czerner [this message]
2019-02-11 17:55   ` [PATCH 2/2] e2fsprogs: fix potential memory leak in path_append() Theodore Y. Ts'o
2019-02-11 16:53 ` [PATCH 1/2] e2freefrag: fix memory leak in scan_online() Theodore Y. Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190115134203.11448-2-lczerner@redhat.com \
    --to=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).