]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: fix PATH_MAX check
authorDarrick J. Wong <djwong@kernel.org>
Mon, 8 Jun 2026 17:03:09 +0000 (10:03 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 2 Jul 2026 19:38:24 +0000 (12:38 -0700)
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: <linux-xfs@vger.kernel.org> # v6.17.0
Fixes: 8a4ea72724930c ("proto: add ability to populate a filesystem from a directory")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
mkfs/proto.c

index a460aebd95ae1e4225d4240a165dc08376b0ed05..e167cba1d8d3ecb205c49f82dfbd4c12baf7586d 100644 (file)
@@ -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);
 
        /*