PERFORCE change 101079 for review
Scott Long
scottl at FreeBSD.org
Sun Jul 9 07:59:53 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=101079
Change 101079 by scottl at 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);
}
More information about the p4-projects
mailing list