From: Utkal Singh <singhutkal015@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: hsiangkao@linux.alibaba.com, Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH] erofs-utils: lib: fix missing NULL checks after strdup() in tarerofs_parse_tar_header()
Date: Sat, 14 Mar 2026 23:10:44 +0000 [thread overview]
Message-ID: <20260314231044.42243-1-singhutkal015@gmail.com> (raw)
strdup() calls for eh.path and eh.link had no NULL check.
On memory allocation failure, eh.path or eh.link would silently
become NULL and get dereferenced later, causing a crash.
Add NULL checks after each strdup() call and return -ENOMEM via
the existing 'out' cleanup label on failure.
Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
lib/tar.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/tar.c b/lib/tar.c
index 26461f8..0963821 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -719,10 +719,20 @@ int tarerofs_parse_tar(struct erofs_importer *im, struct erofs_tarfile *tar)
int ckksum, ret, rem, j;
root->dev = tar->dev;
- if (eh.path)
+ if (eh.path) {
eh.path = strdup(eh.path);
- if (eh.link)
+ if (!eh.path) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ }
+ if (eh.link) {
eh.link = strdup(eh.link);
+ if (!eh.link) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ }
init_list_head(&eh.xattrs);
restart:
--
2.43.0
next reply other threads:[~2026-03-14 23:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 23:10 Utkal Singh [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-03-14 21:25 [PATCH] erofs-utils: lib: fix missing NULL checks after strdup() in tarerofs_parse_tar_header() Utkal Singh
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=20260314231044.42243-1-singhutkal015@gmail.com \
--to=singhutkal015@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.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