Skip to contentSkip to conversation

erofs-utils: fsck: fix extract path length check

PATCH New Vansh Choudhary 1 participant 1 message Apr 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: fsck: fix extract path length check

erofsfsck_dirent_iter() misses the extra '/' and trailing NUL byte when checking if the extraction path still fits in the PATH_MAX-sized buffer.

Account for both bytes to avoid writing past the end of the buffer.

Fixes 27aeef179bf1 ("erofs-utils: fsck: block insane long paths when extracting images")
---
 fsck/main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fsck/main.c +6 -1
index 1254112..daac434 100644
@@ -902,6 +902,7 @@ static int erofsfsck_dirent_iter(struct erofs_dir_context *ctx)
 {
 	int ret;
 	size_t prev_pos, curr_pos;
+	size_t required;
 
 	if (ctx->dot_dotdot)
 		return 0;
@@ -909,7 +910,11 @@ static int erofsfsck_dirent_iter(struct erofs_dir_context *ctx)
 	prev_pos = fsckcfg.extract_pos;
 	curr_pos = prev_pos;
 
-	if (prev_pos + ctx->de_namelen >= PATH_MAX) {
+	required = prev_pos + ctx->de_namelen;
+	if (fsckcfg.extract_path)
+		required += 2;	/* reserve space for '/' and trailing '\0' */
+
+	if (required >= PATH_MAX) {
 		erofs_err("unable to fsck since the path is too long (%llu)",
 			  (curr_pos + ctx->de_namelen) | 0ULL);
 		return -EOPNOTSUPP;
Signature · 1 line
2.43.0