From: Ajay Rajera <newajay.11r@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, Ajay Rajera <newajay.11r@gmail.com>
Subject: [PATCH] erofs-utils: fix resource leaks and missing returns on error paths
Date: Fri, 20 Mar 2026 22:22:00 +0530 [thread overview]
Message-ID: <20260320165200.1862-1-newajay.11r@gmail.com> (raw)
This patch fixes two error-handling bugs in erofs-utils:
1. fuse: add missing return on getattr error
erofsfuse_getattr() calls fuse_reply_err() when erofs_read_inode_from_disk()
fails, but does not return afterwards. This causes the function to fall through
to erofsfuse_fill_stat() with uninitialized inode data and then call
fuse_reply_attr(), sending a second reply to the same FUSE request. This triggers
undefined behavior in libfuse and exposes garbage values.
2. lib: fix memory leak in erofs_gzran_builder_init error path
When inflateInit2() fails, erofs_gzran_builder_init() returns an ERR_PTR(-EFAULT)
but forgets to free the previously allocated erofs_gzran_builder struct (gb),
resulting in a memory leak.
Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
---
fuse/main.c | 4 +++-
lib/gzran.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/fuse/main.c b/fuse/main.c
index 82aca8c..b634782 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -265,8 +265,10 @@ static void erofsfuse_getattr(fuse_req_t req, fuse_ino_t ino,
struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
ret = erofs_read_inode_from_disk(&vi);
- if (ret < 0)
+ if (ret < 0) {
fuse_reply_err(req, -ret);
+ return;
+ }
erofsfuse_fill_stat(&vi, &stbuf);
stbuf.st_ino = ino;
diff --git a/lib/gzran.c b/lib/gzran.c
index dffb20a..8a01825 100644
--- a/lib/gzran.c
+++ b/lib/gzran.c
@@ -50,8 +50,10 @@ struct erofs_gzran_builder *erofs_gzran_builder_init(struct erofs_vfile *vf,
strm->avail_in = 0;
strm->next_in = Z_NULL;
ret = inflateInit2(strm, 47); /* automatic zlib or gzip decoding */
- if (ret != Z_OK)
+ if (ret != Z_OK) {
+ free(gb);
return ERR_PTR(-EFAULT);
+ }
gb->vf = vf;
gb->span_size = span_size;
gb->totout = gb->totin = 0;
--
2.51.0.windows.1
next reply other threads:[~2026-03-20 16:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 16:52 Ajay Rajera [this message]
2026-03-20 17:04 ` [PATCH] erofs-utils: fix resource leaks and missing returns on error paths Nithurshen
2026-03-20 17:20 ` Ajay Rajera
2026-03-20 17:31 ` Nithurshen Karthikeyan
2026-03-21 5:07 ` Nithurshen
2026-03-21 5:16 ` Gao Xiang
2026-03-21 7:15 ` Nithurshen
2026-03-21 13:39 ` Gao Xiang
2026-03-30 4:41 ` Nithurshen Karthikeyan
2026-03-21 6:31 ` Ajay Rajera
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=20260320165200.1862-1-newajay.11r@gmail.com \
--to=newajay.11r@gmail.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@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