From owner-p4-projects@FreeBSD.ORG Sun Jul 9 07:59:53 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id EEEC516A4DE; Sun, 9 Jul 2006 07:59:52 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B07E016A4DA for ; Sun, 9 Jul 2006 07:59:52 +0000 (UTC) (envelope-from scottl@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7B63A43D45 for ; Sun, 9 Jul 2006 07:59:52 +0000 (GMT) (envelope-from scottl@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k697xq1u068776 for ; Sun, 9 Jul 2006 07:59:52 GMT (envelope-from scottl@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k697xqAE068773 for perforce@freebsd.org; Sun, 9 Jul 2006 07:59:52 GMT (envelope-from scottl@freebsd.org) Date: Sun, 9 Jul 2006 07:59:52 GMT Message-Id: <200607090759.k697xqAE068773@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to scottl@freebsd.org using -f From: Scott Long To: Perforce Change Reviews Cc: Subject: PERFORCE change 101079 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Jul 2006 07:59:53 -0000 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); }