linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libhandle: fix potential unterminated string problem
@ 2020-10-08  3:58 Darrick J. Wong
  2020-10-08 21:53 ` Eric Sandeen
  2020-10-15  8:29 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Darrick J. Wong @ 2020-10-08  3:58 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

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>
---
Unless this is supposed to be a memcpy?  But it doesn't look like it.
---
 libhandle/handle.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libhandle/handle.c b/libhandle/handle.c
index eb099f43791e..5c1686b3968d 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;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-15  8:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08  3:58 [PATCH] libhandle: fix potential unterminated string problem Darrick J. Wong
2020-10-08 21:53 ` Eric Sandeen
2020-10-15  8:29 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).