]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
libfrog: fix buffer overflow in getparents path_to_string
authorDarrick J. Wong <djwong@kernel.org>
Thu, 11 Jun 2026 14:05:06 +0000 (07:05 -0700)
committerAndrey Albershteyn <aalbersh@kernel.org>
Wed, 17 Jun 2026 10:49:27 +0000 (12:49 +0200)
Codex points out rather indirectly that snprintf returns the number of
bytes that would be formatted into the buffer excluding the null
terminator.  However, it won't format more bytes than the size
parameter, so the proper way to detect overflows is to compare the
return value against the size parameter.  Fix that.

Cc: linux-xfs@vger.kernel.org # v6.10.0
Fixes: 56f6ba21e97756 ("libfrog: add parent pointer support code")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org>
libfrog/getparents.c

index e8f545392634e49bcffa7c70c2ec57c35200beab..8a53c64332c8391c0619c90bd53bd130884c2839 100644 (file)
@@ -355,7 +355,7 @@ path_to_string(
                mntpt_len--;
 
        ret = snprintf(gpi->buf, gpi->len, "%.*s", mntpt_len, mntpt);
-       if (ret != mntpt_len)
+       if (ret >= gpi->len)
                return ENAMETOOLONG;
        gpi->written += ret;