Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Mar 2011 14:09:30 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Matthew D Fleming <mdf@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r219468 - in head/sys: amd64/amd64 ia64/ia64 powerpc/aim sparc64/sparc64 sun4v/sun4v sys
Message-ID:  <20110311140109.L1003@besplex.bde.org>
In-Reply-To: <201103102256.p2AMu0ww058452@svn.freebsd.org>
References:  <201103102256.p2AMu0ww058452@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 10 Mar 2011, Matthew D Fleming wrote:

> Log:
>  Use MAXPATHLEN rather than the size of an extern array when copying the
>  kernel name.  Also consistenly use strlcpy().
>
>  Suggested by:	Warner Losh

Seems backwards to me.

> Modified: head/sys/amd64/amd64/machdep.c
> ==============================================================================
> --- head/sys/amd64/amd64/machdep.c	Thu Mar 10 22:20:11 2011	(r219467)
> +++ head/sys/amd64/amd64/machdep.c	Thu Mar 10 22:56:00 2011	(r219468)
> @@ -1741,7 +1741,7 @@ hammer_time(u_int64_t modulep, u_int64_t
>
>         env = getenv("kernelname");
> 	if (env != NULL)
> -		strlcpy(kernelname, env, sizeof(kernelname));
> +		strlcpy(kernelname, env, MAXPATHLEN);
>
> #ifdef XENHVM
> 	if (inw(0x10) == 0x49d2) {
>

The strlcpy() won't save you if the size of the array changes, since the
size is now hard-coded.

> ...
> Modified: head/sys/sys/kernel.h
> ==============================================================================
> --- head/sys/sys/kernel.h	Thu Mar 10 22:20:11 2011	(r219467)
> +++ head/sys/sys/kernel.h	Thu Mar 10 22:56:00 2011	(r219468)
> @@ -55,7 +55,7 @@
> /* Global variables for the kernel. */
>
> /* 1.1 */
> -extern char kernelname[MAXPATHLEN];
> +extern char kernelname[/*MAXPATHLEN*/];
>
> extern int tick;			/* usec per tick (1000000 / hz) */
> extern int hz;				/* system clock's frequency */
>

This commit seems to be part of reducing namespace pollution, but MAXPATHLEN
is always available in the kernel since it is in <sys/param.h> which is a
prerequisite for almost all kernel headers.  This is one reason why PATH_MAX
is spelled MAXPATHLEN in the kernel.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110311140109.L1003>