All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yifan Zhao <stopire@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: Yifan Zhao <stopire@gmail.com>
Subject: [PATCH 5/8] erofs-utils: exclude: fix stack overflow when checking long paths
Date: Thu, 12 Nov 2026 20:47:22 +0800	[thread overview]
Message-ID: <20261112124725.2774244-6-stopire@gmail.com> (raw)
In-Reply-To: <20261112124725.2774244-1-stopire@gmail.com>

Assisted-by: Codex:gpt-6-astra
Assisted-by: Claude Code:deepseek-v4.1-flash-1017
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
 lib/exclude.c | 7 ++++++-
 lib/inode.c   | 8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/exclude.c b/lib/exclude.c
index 6beb46b..487da6a 100644
--- a/lib/exclude.c
+++ b/lib/exclude.c
@@ -108,7 +108,12 @@ struct erofs_exclude_rule *erofs_is_exclude_path(const char *dir,
 		/* no prefix */
 		s = name;
 	} else {
-		sprintf(buf, "%s/%s", dir, name);
+		int ret = snprintf(buf, sizeof(buf), "%s/%s", dir, name);
+
+		if (ret < 0)
+			return ERR_PTR(-errno);
+		if ((size_t)ret >= sizeof(buf))
+			return ERR_PTR(-ENAMETOOLONG);
 		s = buf;
 	}
 
diff --git a/lib/inode.c b/lib/inode.c
index 3108aa0..f687857 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1851,6 +1851,7 @@ static int erofs_mkfs_import_localdir(struct erofs_importer *im, struct erofs_in
 	__nr_subdirs = *nr_subdirs;
 	__nlink = *i_nlink;
 	while (1) {
+		struct erofs_exclude_rule *rule;
 		struct erofs_inode *inode;
 		struct erofs_dentry *d;
 		char buf[PATH_MAX];
@@ -1873,7 +1874,12 @@ static int erofs_mkfs_import_localdir(struct erofs_importer *im, struct erofs_in
 			continue;
 
 		/* skip if it's a exclude file */
-		if (erofs_is_exclude_path(dir->i_srcpath, dp->d_name))
+		rule = erofs_is_exclude_path(dir->i_srcpath, dp->d_name);
+		if (IS_ERR(rule)) {
+			ret = PTR_ERR(rule);
+			goto err_closedir;
+		}
+		if (rule)
 			continue;
 
 		d = erofs_d_alloc(dir, dp->d_name);
-- 
2.56.0



  parent reply	other threads:[~2026-11-12 12:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 12:47 [PATCH 0/8] erofs-utils: fix issues found by LLMs Yifan Zhao
2026-11-12 12:47 ` [PATCH 1/8] erofs-utils: lib: fix arithmetic overflow in large file handling Yifan Zhao
2026-11-12 12:47 ` [PATCH 2/8] erofs-utils: mkfs: fix incremental superblock stack overread Yifan Zhao
2026-11-12 12:47 ` [PATCH 3/8] erofs-utils: tar: fix out-of-bounds access when trimming PAX paths Yifan Zhao
2026-11-12 12:47 ` [PATCH 4/8] erofs-utils: lib: fix buffer leaks in error paths Yifan Zhao
2026-11-12 23:20   ` Gao Xiang
2026-11-12 12:47 ` Yifan Zhao [this message]
2026-11-12 12:47 ` [PATCH 6/8] erofs-utils: lib: fix gzran EOF handling and state leaks Yifan Zhao
2026-11-12 12:47 ` [PATCH 7/8] erofs-utils: lib: fix metabox inline data reads Yifan Zhao
2026-11-12 12:47 ` [PATCH 8/8] erofs-utils: fix read error and short read handling Yifan Zhao
2026-11-12 23:41   ` Gao Xiang

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=20261112124725.2774244-6-stopire@gmail.com \
    --to=stopire@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.