git: 0bd4c448ec1d - main - Rewrite to avoid Coverity false positive.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 26 Jan 2023 01:01:41 UTC
The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=0bd4c448ec1dfdc2300a6cacca42e1fc7c4d8f14 commit 0bd4c448ec1dfdc2300a6cacca42e1fc7c4d8f14 Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2023-01-26 00:57:26 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2023-01-26 00:57:26 +0000 Rewrite to avoid Coverity false positive. MFC after: 1 week Reported by: Coverity (CID 1502669) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37907 --- sbin/mount/getmntopts.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c index e6607c385341..7702da903749 100644 --- a/sbin/mount/getmntopts.c +++ b/sbin/mount/getmntopts.c @@ -166,6 +166,7 @@ getmntpoint(const char *name) char *ddevname; struct statfs *mntbuf, *statfsp; int i, mntsize, isdev; + u_long len; if (stat(name, &devstat) != 0) return (NULL); @@ -178,12 +179,13 @@ getmntpoint(const char *name) statfsp = &mntbuf[i]; ddevname = statfsp->f_mntfromname; if (*ddevname != '/') { - if (strlen(_PATH_DEV) + strlen(ddevname) + 1 > - sizeof(statfsp->f_mntfromname)) + if ((len = strlen(_PATH_DEV) + strlen(ddevname) + 1) > + sizeof(statfsp->f_mntfromname) || + len > sizeof(device)) continue; - strcpy(device, _PATH_DEV); - strcat(device, ddevname); - strcpy(statfsp->f_mntfromname, device); + strncpy(device, _PATH_DEV, len); + strncat(device, ddevname, len); + strncpy(statfsp->f_mntfromname, device, len); } if (isdev == 0) { if (strcmp(name, statfsp->f_mntonname))