From: Eric Sandeen <sandeen@sandeen.net>
To: "Darrick J. Wong" <darrick.wong@oracle.com>,
Eric Sandeen <sandeen@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] libhandle: fix potential unterminated string problem
Date: Thu, 8 Oct 2020 16:53:11 -0500 [thread overview]
Message-ID: <a75ac669-164f-23fe-6293-13c183960f84@sandeen.net> (raw)
In-Reply-To: <20201008035834.GB6535@magnolia>
On 10/7/20 10:58 PM, Darrick J. Wong wrote:
> 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.
so FWIW, coverity has complained about this one forever, CID 1297520
I think the thing that kept me from addressing it before was uncertainty
around lopping one byte off of PATH_MAX / MAXPATHLEN, essentially.
In reality, I think (?) PATH_MAX is a bit of a fiction anyway, and
there's probably nothing special about that one byte, and I think (?)
this is always a path to a mountpoint (?) which is unlikely to be 4096
or 4095 chars long anyway (?) so ... um ... sure.
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 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 prev parent reply other threads:[~2020-10-08 21:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-08 3:58 [PATCH] libhandle: fix potential unterminated string problem Darrick J. Wong
2020-10-08 21:53 ` Eric Sandeen [this message]
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=a75ac669-164f-23fe-6293-13c183960f84@sandeen.net \
--to=sandeen@sandeen.net \
--cc=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).