From: Darrick J. Wong Date: Mon, 12 Oct 2020 15:59:19 +0000 (-0400) Subject: libhandle: fix potential unterminated string problem X-Git-Tag: v5.9.0-rc1~6 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=f4d026454335c4808b5ab8aa44e4eb51a916d9ff;p=thirdparty%2Fxfsprogs-dev.git libhandle: fix potential unterminated string problem gcc 10.2 complains about the strncpy call here, since it's possible that the source string is so long that the fspath inside the fdhash structure will end up without a null terminator. Work around strncpy braindamage yet again by forcing the string to be terminated properly. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- diff --git a/libhandle/handle.c b/libhandle/handle.c index eb099f437..5c1686b39 100644 --- a/libhandle/handle.c +++ b/libhandle/handle.c @@ -107,7 +107,8 @@ path_to_fshandle( } fdhp->fsfd = fd; - strncpy(fdhp->fspath, fspath, sizeof(fdhp->fspath)); + strncpy(fdhp->fspath, fspath, sizeof(fdhp->fspath) - 1); + fdhp->fspath[sizeof(fdhp->fspath) - 1] = 0; memcpy(fdhp->fsh, *fshanp, FSIDSIZE); fdhp->fnxt = fdhash_head;