PERFORCE change 100021 for review

John Birrell jb at FreeBSD.org
Mon Jun 26 05:21:05 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=100021

Change 100021 by jb at jb_freebsd2 on 2006/06/26 05:20:36

	Remove the length limitation on kernel getenv() strings. The sx
	lock allows a malloc while the lock is held, so why not simplify
	the code and avoid copying the string to a temporary (size limited)
	string.
	
	This allows large kenv strings to be passed from the boot loader.
	
	The length limitation still applies in kenv(1) when setting a
	string. I think it should be removed from there too. It's a pretty
	silly limit in this day and age when we often have gobs of memory.
	
	kenv(1) has no difficulty reporting the long strings.
	
	This is required so that the anonymous enablings can be passed
	to the kernel from the boot loader.

Affected files ...

.. //depot/projects/dtrace/src/sys/kern/kern_environment.c#2 edit

Differences ...

==== //depot/projects/dtrace/src/sys/kern/kern_environment.c#2 (text+ko) ====

@@ -283,7 +283,6 @@
 char *
 getenv(const char *name)
 {
-	char buf[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
 	char *ret, *cp;
 	int len;
 
@@ -291,11 +290,10 @@
 		sx_slock(&kenv_lock);
 		cp = _getenv_dynamic(name, NULL);
 		if (cp != NULL) {
-			strcpy(buf, cp);
+			len = strlen(cp) + 1;
+			ret = malloc(len, M_KENV, M_WAITOK);
+			strcpy(ret, cp);
 			sx_sunlock(&kenv_lock);
-			len = strlen(buf) + 1;
-			ret = malloc(len, M_KENV, M_WAITOK);
-			strcpy(ret, buf);
 		} else {
 			sx_sunlock(&kenv_lock);
 			ret = NULL;


More information about the p4-projects mailing list