aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2023-01-26 00:57:26 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2023-01-26 00:57:26 +0000
commit0bd4c448ec1dfdc2300a6cacca42e1fc7c4d8f14 (patch)
tree693a8fcbdc9729b75bbe08fb8bd80ba4728f20d5
parenta04aa80e773a4bfdc4e72bab85d6e16f0083745e (diff)
downloadsrc-0bd4c448ec1dfdc2300a6cacca42e1fc7c4d8f14.tar.gz
src-0bd4c448ec1dfdc2300a6cacca42e1fc7c4d8f14.zip
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
-rw-r--r--sbin/mount/getmntopts.c12
1 files 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))