Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD: Fix leaked strings in libspl mnttab #12961

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions lib/libspl/os/freebsd/mnttab.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,28 @@ optadd(char *mntopts, size_t size, const char *opt)
strlcat(mntopts, opt, size);
}

static __thread char gfstypename[MFSNAMELEN];
static __thread char gmntfromname[MNAMELEN];
static __thread char gmntonname[MNAMELEN];
static __thread char gmntopts[MNTMAXSTR];

void
statfs2mnttab(struct statfs *sfs, struct mnttab *mp)
{
static char mntopts[MNTMAXSTR];
long flags;

mntopts[0] = '\0';
strlcpy(gfstypename, sfs->f_fstypename, sizeof (gfstypename));
mp->mnt_fstype = gfstypename;

strlcpy(gmntfromname, sfs->f_mntfromname, sizeof (gmntfromname));
mp->mnt_special = gmntfromname;

strlcpy(gmntonname, sfs->f_mntonname, sizeof (gmntonname));
mp->mnt_mountp = gmntonname;

flags = sfs->f_flags;
#define OPTADD(opt) optadd(mntopts, sizeof (mntopts), (opt))
gmntopts[0] = '\0';
#define OPTADD(opt) optadd(gmntopts, sizeof (gmntopts), (opt))
if (flags & MNT_RDONLY)
OPTADD(MNTOPT_RO);
else
Expand All @@ -121,10 +133,7 @@ statfs2mnttab(struct statfs *sfs, struct mnttab *mp)
else
OPTADD(MNTOPT_EXEC);
#undef OPTADD
mp->mnt_special = strdup(sfs->f_mntfromname);
mp->mnt_mountp = strdup(sfs->f_mntonname);
mp->mnt_fstype = strdup(sfs->f_fstypename);
mp->mnt_mntopts = strdup(mntopts);
mp->mnt_mntopts = gmntopts;
}

static struct statfs *gsfs = NULL;
Expand Down Expand Up @@ -166,7 +175,6 @@ statfs_init(void)
int
getmntany(FILE *fd __unused, struct mnttab *mgetp, struct mnttab *mrefp)
{
// struct statfs *sfs;
int i, error;

error = statfs_init();
Expand Down Expand Up @@ -195,7 +203,6 @@ getmntany(FILE *fd __unused, struct mnttab *mgetp, struct mnttab *mrefp)
int
getmntent(FILE *fp, struct mnttab *mp)
{
// struct statfs *sfs;
int error, nfs;

nfs = (int)lseek(fileno(fp), 0, SEEK_CUR);
Expand Down