Date: Tue, 11 May 2010 16:08:30 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 178102 for review Message-ID: <201005111608.o4BG8UlQ031491@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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'; + } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005111608.o4BG8UlQ031491>