FreeBSD: do_mount() passes wrong string length to helper

It should pass `MNT_LINE_MAX`, but passes `sizeof (mntpt)`. This is
harmless because the strlen is not actually used by the helper, but
FreeBSD's Coverity scans complained about it.

This was missed in my audit of various string functions since it is not
actually passed to a string function.

Upon review, it was noticed that the helper function does not need to be
a separate function, so I have inlined it as cleanup.

Reported-by: Coverity (CID 1432079)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: szubersk <szuberskidamian@gmail.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14136
This commit is contained in:
Richard Yao 2022-11-03 13:53:17 -04:00 committed by Brian Behlendorf
parent 31247c78b1
commit 0a0166c975
1 changed files with 8 additions and 18 deletions

View File

@ -73,33 +73,30 @@ build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val,
*iovlen = ++i; *iovlen = ++i;
} }
static int int
do_mount_(const char *spec, const char *dir, int mflag, do_mount(zfs_handle_t *zhp, const char *mntpt, const char *opts, int flags)
char *dataptr, int datalen, const char *optptr, int optlen)
{ {
struct iovec *iov; struct iovec *iov;
char *optstr, *p, *tofree; char *optstr, *p, *tofree;
int iovlen, rv; int iovlen, rv;
const char *spec = zfs_get_name(zhp);
assert(spec != NULL); assert(spec != NULL);
assert(dir != NULL); assert(mntpt != NULL);
assert(dataptr == NULL), (void) dataptr; assert(opts != NULL);
assert(datalen == 0), (void) datalen;
assert(optptr != NULL);
assert(optlen > 0), (void) optlen;
tofree = optstr = strdup(optptr); tofree = optstr = strdup(opts);
assert(optstr != NULL); assert(optstr != NULL);
iov = NULL; iov = NULL;
iovlen = 0; iovlen = 0;
if (strstr(optstr, MNTOPT_REMOUNT) != NULL) if (strstr(optstr, MNTOPT_REMOUNT) != NULL)
build_iovec(&iov, &iovlen, "update", NULL, 0); build_iovec(&iov, &iovlen, "update", NULL, 0);
if (mflag & MS_RDONLY) if (flags & MS_RDONLY)
build_iovec(&iov, &iovlen, "ro", NULL, 0); build_iovec(&iov, &iovlen, "ro", NULL, 0);
build_iovec(&iov, &iovlen, "fstype", __DECONST(char *, MNTTYPE_ZFS), build_iovec(&iov, &iovlen, "fstype", __DECONST(char *, MNTTYPE_ZFS),
(size_t)-1); (size_t)-1);
build_iovec(&iov, &iovlen, "fspath", __DECONST(char *, dir), build_iovec(&iov, &iovlen, "fspath", __DECONST(char *, mntpt),
(size_t)-1); (size_t)-1);
build_iovec(&iov, &iovlen, "from", __DECONST(char *, spec), (size_t)-1); build_iovec(&iov, &iovlen, "from", __DECONST(char *, spec), (size_t)-1);
while ((p = strsep(&optstr, ",/")) != NULL) while ((p = strsep(&optstr, ",/")) != NULL)
@ -109,14 +106,7 @@ do_mount_(const char *spec, const char *dir, int mflag,
if (rv < 0) if (rv < 0)
return (errno); return (errno);
return (rv); return (rv);
}
int
do_mount(zfs_handle_t *zhp, const char *mntpt, const char *opts, int flags)
{
return (do_mount_(zfs_get_name(zhp), mntpt, flags, NULL, 0,
opts, sizeof (mntpt)));
} }
int int