Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Aug 2012 19:16:30 +0000 (UTC)
From:      Jaakko Heinonen <jh@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r239257 - head/sys/kern
Message-ID:  <201208141916.q7EJGUHd039313@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jh
Date: Tue Aug 14 19:16:30 2012
New Revision: 239257
URL: http://svn.freebsd.org/changeset/base/239257

Log:
  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:
  head/sys/kern/kern_environment.c

Modified: head/sys/kern/kern_environment.c
==============================================================================
--- head/sys/kern/kern_environment.c	Tue Aug 14 17:53:52 2012	(r239256)
+++ head/sys/kern/kern_environment.c	Tue Aug 14 19:16:30 2012	(r239257)
@@ -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);



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