PERFORCE change 178102 for review

Garrett Cooper gcooper at FreeBSD.org
Tue May 11 16:08:31 UTC 2010


http://p4web.freebsd.org/@@178102?ac=10

Change 178102 by gcooper at 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';
+                                        }
 
 				}
 


More information about the p4-projects mailing list