Small bug in sys/kern/vfs_mountroot.c

J David j.david.lists at
Mon Sep 9 00:17:21 UTC 2013

In releng/9.2 (and possibly other versions), in kern/vfs_mountroot.c,
in parse_mount, there appears to be a small bug.

The expression sizeof(errmsg) is used in a strlcpy.  This would work
if errmsg were an array, but it's a char*, so sizeof() returns the
pointer's size and this limits the error message to seven characters +
NULL (on amd64), translating "unknown file system" into the moderately
less helpful "unknown."

A "patch" is below.  (It's a tiny fix.)

Index: vfs_mountroot.c
--- vfs_mountroot.c (revision 255409)
+++ vfs_mountroot.c (working copy)
@@ -709,7 +709,7 @@
  errmsg = malloc(ERRMSGL, M_TEMP, M_WAITOK | M_ZERO);

  if (vfs_byname(fs) == NULL) {
- strlcpy(errmsg, "unknown file system", sizeof(errmsg));
+ strlcpy(errmsg, "unknown file system", ERRMSGL);
  error = ENOENT;
  goto out;

More information about the freebsd-stable mailing list