svn commit: r187130 - head/sbin/mount

David E. O'Brien obrien at FreeBSD.org
Mon Jan 12 22:08:38 PST 2009


Author: obrien
Date: Tue Jan 13 06:08:37 2009
New Revision: 187130
URL: http://svn.freebsd.org/changeset/base/187130

Log:
  r187093 failed to keep the lifetime of the pointer suitable for reentrancy.
  Fix that.  Also move the current buffer size into the 'cpa' structure.

Modified:
  head/sbin/mount/mount.c

Modified: head/sbin/mount/mount.c
==============================================================================
--- head/sbin/mount/mount.c	Tue Jan 13 05:50:22 2009	(r187129)
+++ head/sbin/mount/mount.c	Tue Jan 13 06:08:37 2009	(r187130)
@@ -70,6 +70,7 @@ int debug, fstab_style, verbose;
 
 struct cpa {
 	char	**a;
+	ssize_t	sz;
 	int	c;
 };
 
@@ -503,11 +504,9 @@ hasopt(const char *mntopts, const char *
 static void
 append_arg(struct cpa *sa, char *arg)
 {
-	static int a_sz;
-
-	if (sa->c + 1 == a_sz) {
-		a_sz = a_sz == 0 ? 8 : a_sz * 2;
-		sa->a = realloc(sa->a, sizeof(sa->a) * a_sz);
+	if (sa->c + 1 == sa->sz) {
+		sa->sz = sa->sz == 0 ? 8 : sa->sz * 2;
+		sa->a = realloc(sa->a, sizeof(sa->a) * sa->sz);
 		if (sa->a == NULL)
 			errx(1, "realloc failed");
 	}
@@ -518,11 +517,10 @@ int
 mountfs(const char *vfstype, const char *spec, const char *name, int flags,
 	const char *options, const char *mntopts)
 {
-	struct cpa mnt_argv;
 	struct statfs sf;
 	int i, ret;
 	char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
-	static int mnt_argv_inited;
+	static struct cpa mnt_argv;
 
 	/* resolve the mountpoint with realpath(3) */
 	(void)checkpath(name, mntpath);
@@ -557,10 +555,6 @@ mountfs(const char *vfstype, const char 
 	/* Construct the name of the appropriate mount command */
 	(void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
 
-	if (!mnt_argv_inited) {
-		mnt_argv_inited++;
-		mnt_argv.a = NULL;
-	}
 	mnt_argv.c = -1;
 	append_arg(&mnt_argv, execname);
 	mangle(optbuf, &mnt_argv);


More information about the svn-src-all mailing list