From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH] libhandle: fix potential unterminated string problem
Date: Wed, 7 Oct 2020 20:58:34 -0700 [thread overview]
Message-ID: <20201008035834.GB6535@magnolia> (raw)
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;
next reply other threads:[~2020-10-08 4:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-08 3:58 Darrick J. Wong [this message]
2020-10-08 21:53 ` [PATCH] libhandle: fix potential unterminated string problem Eric Sandeen
2020-10-15 8:29 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201008035834.GB6535@magnolia \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).