From: Darrick J. Wong Date: Mon, 8 Jun 2026 17:03:09 +0000 (-0700) Subject: mkfs: fix PATH_MAX check X-Git-Tag: v7.1.0~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2df5f48fb8291f28fd07e4b097259cce82ca0172;p=thirdparty%2Fxfsprogs-dev.git mkfs: fix PATH_MAX check Per the snprintf manpage, the correct means to check snprintf for an insufficiently large buffer is to check if its return value is >= @size, not > @size. Codex found this. Cc: # v6.17.0 Fixes: 8a4ea72724930c ("proto: add ability to populate a filesystem from a directory") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- diff --git a/mkfs/proto.c b/mkfs/proto.c index a460aebd9..e167cba1d 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -1674,7 +1674,7 @@ handle_direntry( /* Ensure we're within the limits of PATH_MAX. */ size_t avail = PATH_MAX - path_len; size_t wrote = snprintf(path_buf + path_len, avail, "/%s", entry->d_name); - if (wrote > avail) + if (wrote >= avail) fail(path_buf, ENAMETOOLONG); /*