git: e11fe183004b - stable/13 - Rewrite to avoid Coverity false positive.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 06 Feb 2023 23:17:57 UTC
The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=e11fe183004beaba7ec25b120c7394732fdef680 commit e11fe183004beaba7ec25b120c7394732fdef680 Author: Kirk McKusick <mckusick@FreeBSD.org> AuthorDate: 2023-01-26 00:57:26 +0000 Commit: Kirk McKusick <mckusick@FreeBSD.org> CommitDate: 2023-02-06 23:17:39 +0000 Rewrite to avoid Coverity false positive. Reported by: Coverity (CID 1502669) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37907 (cherry picked from commit 0bd4c448ec1dfdc2300a6cacca42e1fc7c4d8f14) --- 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))