[Midnightbsd-cvs] src [7823] trunk/sys/kern/vfs_mountroot.c: do not allocate buffer of the 255 bytes length on the stack

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Sep 6 19:56:16 EDT 2016


Revision: 7823
          http://svnweb.midnightbsd.org/src/?rev=7823
Author:   laffer1
Date:     2016-09-06 19:56:15 -0400 (Tue, 06 Sep 2016)
Log Message:
-----------
do not allocate buffer of the 255 bytes length on the stack

Modified Paths:
--------------
    trunk/sys/kern/vfs_mountroot.c

Modified: trunk/sys/kern/vfs_mountroot.c
===================================================================
--- trunk/sys/kern/vfs_mountroot.c	2016-09-06 23:54:17 UTC (rev 7822)
+++ trunk/sys/kern/vfs_mountroot.c	2016-09-06 23:56:15 UTC (rev 7823)
@@ -672,10 +672,11 @@
 	return (error != 0) ? 0 : 1;
 }
 
+#define	ERRMSGL	255
 static int
 parse_mount(char **conf)
 {
-	char errmsg[255];
+	char *errmsg;
 	struct mntarg *ma;
 	char *dev, *fs, *opts, *tok;
 	int delay, error, timeout;
@@ -707,7 +708,7 @@
 	printf("Trying to mount root from %s:%s [%s]...\n", fs, dev,
 	    (opts != NULL) ? opts : "");
 
-	bzero(errmsg, sizeof(errmsg));
+	errmsg = malloc(ERRMSGL, M_TEMP, M_WAITOK | M_ZERO);
 
 	if (vfs_byname(fs) == NULL) {
 		strlcpy(errmsg, "unknown file system", sizeof(errmsg));
@@ -734,7 +735,7 @@
 	ma = mount_arg(ma, "fstype", fs, -1);
 	ma = mount_arg(ma, "fspath", "/", -1);
 	ma = mount_arg(ma, "from", dev, -1);
-	ma = mount_arg(ma, "errmsg", errmsg, sizeof(errmsg));
+	ma = mount_arg(ma, "errmsg", errmsg, ERRMSGL);
 	ma = mount_arg(ma, "ro", NULL, 0);
 	ma = parse_mountroot_options(ma, opts);
 	error = kernel_mount(ma, MNT_ROOTFS);
@@ -748,11 +749,13 @@
 		printf(".\n");
 	}
 	free(fs, M_TEMP);
+	free(errmsg, M_TEMP);
 	if (opts != NULL)
 		free(opts, M_TEMP);
 	/* kernel_mount can return -1 on error. */
 	return ((error < 0) ? EDOOFUS : error);
 }
+#undef ERRMSGL
 
 static int
 vfs_mountroot_parse(struct sbuf *sb, struct mount *mpdevfs)



More information about the Midnightbsd-cvs mailing list