Date: Sun, 9 Jul 2006 07:59:52 GMT From: Scott Long <scottl@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 101079 for review Message-ID: <200607090759.k697xqAE068773@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=101079 Change 101079 by scottl@scottl-wv1u on 2006/07/09 07:59:10 Short-circuit the temp buffer if kenv(KENV_DUMP) is called with a length of 0 or a NULL buffer. ALso remove a redundant check. Affected files ... .. //depot/projects/scottl-camlock/src/sys/kern/kern_environment.c#8 edit Differences ... ==== //depot/projects/scottl-camlock/src/sys/kern/kern_environment.c#8 (text+ko) ==== @@ -85,7 +85,7 @@ int len; } */ *uap; { - char *name, *value, *buffer; + char *name, *value, *buffer = NULL; size_t len, done, needed; int error, i; @@ -99,7 +99,8 @@ return (error); #endif done = needed = 0; - buffer = malloc(uap->len, M_TEMP, M_WAITOK|M_ZERO); + if (uap->len > 0 && uap->value != NULL) + buffer = malloc(uap->len, M_TEMP, M_WAITOK|M_ZERO); mtx_lock(&kenv_lock); for (i = 0; kenvp[i] != NULL; i++) { len = strlen(kenvp[i]) + 1; @@ -109,16 +110,16 @@ * If called with a NULL or insufficiently large * buffer, just keep computing the required size. */ - if (uap->value != NULL && len > 0) { - if (done + len > uap->len) - break; + if (uap->value != NULL && buffer != NULL && len > 0) { bcopy(kenvp[i], buffer + done, len); done += len; } } mtx_unlock(&kenv_lock); - error = copyout(buffer, uap->value, done); - free(buffer, M_TEMP); + if (buffer != NULL) { + error = copyout(buffer, uap->value, done); + free(buffer, M_TEMP); + } td->td_retval[0] = ((done == needed) ? 0 : needed); return (error); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607090759.k697xqAE068773>