Skip to content

Commit

Permalink
Do not allocate buffer of the 255 bytes length on the stack.
Browse files Browse the repository at this point in the history
Reported and tested by:	[email protected]
MFC after:	1 week
  • Loading branch information
kostikbel committed Dec 4, 2012
1 parent e3194b8 commit f366a4a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sys/kern/vfs_mountroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,11 @@ parse_mount_dev_present(const char *dev)
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;
Expand Down Expand Up @@ -707,7 +708,7 @@ parse_mount(char **conf)
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));
Expand All @@ -734,7 +735,7 @@ parse_mount(char **conf)
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);
Expand All @@ -748,11 +749,13 @@ parse_mount(char **conf)
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)
Expand Down

0 comments on commit f366a4a

Please sign in to comment.