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>
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;