]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libhandle: fix potential unterminated string problem
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 12 Oct 2020 15:59:19 +0000 (11:59 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Mon, 12 Oct 2020 15:59:19 +0000 (11:59 -0400)
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 <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libhandle/handle.c

index eb099f43791ec2e5fa4df08e063b27537756f6d5..5c1686b3968dc706fd682b8f4c4d0efcdfdafc06 100644 (file)
@@ -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;