svn commit: r241222 - stable/9/sys/kern

Jaakko Heinonen jh at FreeBSD.org
Fri Oct 5 09:47:55 UTC 2012


Author: jh
Date: Fri Oct  5 09:47:54 2012
New Revision: 241222
URL: http://svn.freebsd.org/changeset/base/241222

Log:
  MFC r239257:
  
  Reserve room for the terminating NUL when setting or getting kernel
  environment variables. KENV_MNAMELEN and KENV_MVALLEN doesn't include
  space for the terminating NUL.

Modified:
  stable/9/sys/kern/kern_environment.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)
  stable/9/sys/dev/   (props changed)
  stable/9/sys/dev/e1000/   (props changed)
  stable/9/sys/dev/isp/   (props changed)
  stable/9/sys/dev/ixgbe/   (props changed)
  stable/9/sys/dev/puc/   (props changed)
  stable/9/sys/fs/   (props changed)
  stable/9/sys/fs/ntfs/   (props changed)
  stable/9/sys/modules/   (props changed)

Modified: stable/9/sys/kern/kern_environment.c
==============================================================================
--- stable/9/sys/kern/kern_environment.c	Fri Oct  5 07:51:21 2012	(r241221)
+++ stable/9/sys/kern/kern_environment.c	Fri Oct  5 09:47:54 2012	(r241222)
@@ -143,9 +143,9 @@ sys_kenv(td, uap)
 		break;
 	}
 
-	name = malloc(KENV_MNAMELEN, M_TEMP, M_WAITOK);
+	name = malloc(KENV_MNAMELEN + 1, M_TEMP, M_WAITOK);
 
-	error = copyinstr(uap->name, name, KENV_MNAMELEN, NULL);
+	error = copyinstr(uap->name, name, KENV_MNAMELEN + 1, NULL);
 	if (error)
 		goto done;
 
@@ -176,8 +176,8 @@ sys_kenv(td, uap)
 			error = EINVAL;
 			goto done;
 		}
-		if (len > KENV_MVALLEN)
-			len = KENV_MVALLEN;
+		if (len > KENV_MVALLEN + 1)
+			len = KENV_MVALLEN + 1;
 		value = malloc(len, M_TEMP, M_WAITOK);
 		error = copyinstr(uap->value, value, len, NULL);
 		if (error) {
@@ -389,10 +389,10 @@ setenv(const char *name, const char *val
 	KENV_CHECK;
 
 	namelen = strlen(name) + 1;
-	if (namelen > KENV_MNAMELEN)
+	if (namelen > KENV_MNAMELEN + 1)
 		return (-1);
 	vallen = strlen(value) + 1;
-	if (vallen > KENV_MVALLEN)
+	if (vallen > KENV_MVALLEN + 1)
 		return (-1);
 	buf = malloc(namelen + vallen, M_KENV, M_WAITOK);
 	sprintf(buf, "%s=%s", name, value);


More information about the svn-src-stable-9 mailing list