From owner-p4-projects@FreeBSD.ORG Tue May 11 16:08:30 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C9ED9106567B; Tue, 11 May 2010 16:08:30 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 763631065670 for ; Tue, 11 May 2010 16:08:30 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 6428D8FC1E for ; Tue, 11 May 2010 16:08:30 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o4BG8U8b031493 for ; Tue, 11 May 2010 16:08:30 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o4BG8UlQ031491 for perforce@freebsd.org; Tue, 11 May 2010 16:08:30 GMT (envelope-from gcooper@FreeBSD.org) Date: Tue, 11 May 2010 16:08:30 GMT Message-Id: <201005111608.o4BG8UlQ031491@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 178102 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2010 16:08:31 -0000 http://p4web.freebsd.org/@@178102?ac=10 Change 178102 by gcooper@starr on 2010/05/11 16:08:27 Convert a strlcpy for prefix to a one-time strlen and change it to a strcpy. This is an optimization to not have to deal with checking error, passing more crud across the stack, etc. Affected files ... .. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#12 edit Differences ... ==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#12 (text+ko) ==== @@ -533,6 +533,7 @@ PATH_MAX) error = strerror(ENAMETOOLONG); + /* Same as above, if srcbase is NULL. */ if (srcbase != NULL) if (strlcat(srcfile, srcbase, PATH_MAX) > PATH_MAX) @@ -557,19 +558,23 @@ * whitespace. */ assert(prefix != NULL); + + /* + * NOTE (gcooper): strcpy is safe here so long + * as the buffers are of equal size, and also + * because the value has been sanitized below + * and because of the assert above. + */ + strcpy(destbase, prefix); - /* Reset destbase */ - if (strlcpy(destbase, prefix, PATH_MAX) > - PATH_MAX) - error = strerror(ENAMETOOLONG); - /* Reset srcbase */ /* Tack BaseDir on the front if defined. */ if (BaseDir != NULL) { if (strlcpy(srcbase, BaseDir, PATH_MAX) > PATH_MAX) error = strerror(ENAMETOOLONG); - if (strlcpy(srcbase, prefix, PATH_MAX) > + + if (strlcpy(srcbase, prefix, PATH_MAX) > PATH_MAX) error = strerror(ENAMETOOLONG); @@ -583,18 +588,24 @@ /* First @cwd -- wewt! */ if (prefix == NULL) { - prefix = p->name; + if (strlen(prefix) > MAX_PATH) + error = strerror(ENAMETOOLONG); + else { + + prefix = p->name; - /* - * Tack BaseDir on the front if - * defined and this is the first run. - */ - if (BaseDir != NULL) { - if (strlcpy(srcbase, BaseDir, - PATH_MAX) > PATH_MAX) - error = strerror(ENAMETOOLONG); - } else - srcbase[0] = '\0'; + /* + * Tack BaseDir on the front if + * defined and this is the first run. + */ + if (BaseDir != NULL) { + if (strlcpy(srcbase, + BaseDir, PATH_MAX) > + PATH_MAX) + error = strerror(ENAMETOOLONG); + } else + srcbase[0] = '\0'; + } }