Loading...
src/dyld.cpp dyld-360.21 dyld-360.17
--- dyld/dyld-360.21/src/dyld.cpp
+++ dyld/dyld-360.17/src/dyld.cpp
@@ -1190,8 +1190,7 @@
 {
 	//dyld::log("checkDylibOverridesInDir('%s')\n", dirPath);
 	char dylibPath[PATH_MAX];
-	int dirPathLen = strlcpy(dylibPath, dirPath, PATH_MAX-1);
-	if ( dirPathLen >= PATH_MAX )
+	if ( strlcpy(dylibPath, dirPath, PATH_MAX) >= PATH_MAX )
 		return;
 	DIR* dirp = opendir(dirPath);
 	if ( dirp != NULL) {
@@ -1202,8 +1201,8 @@
 				break;
 			if ( entp->d_type != DT_REG ) 
 				continue;
-			dylibPath[dirPathLen] = '/';
-			dylibPath[dirPathLen+1] = '\0';
+			if ( strlcat(dylibPath, "/", PATH_MAX) >= PATH_MAX )
+				continue;
 			if ( strlcat(dylibPath, entp->d_name, PATH_MAX) >= PATH_MAX )
 				continue;
 			checkDylibOverride(dylibPath);
@@ -1217,8 +1216,7 @@
 {
 	//dyld::log("checkFrameworkOverridesInDir('%s')\n", dirPath);
 	char frameworkPath[PATH_MAX];
-	int dirPathLen = strlcpy(frameworkPath, dirPath, PATH_MAX-1);
-	if ( dirPathLen >= PATH_MAX )
+	if ( strlcpy(frameworkPath, dirPath, PATH_MAX) >= PATH_MAX )
 		return;
 	DIR* dirp = opendir(dirPath);
 	if ( dirp != NULL) {
@@ -1229,9 +1227,9 @@
 				break;
 			if ( entp->d_type != DT_DIR ) 
 				continue;
-			frameworkPath[dirPathLen] = '/';
-			frameworkPath[dirPathLen+1] = '\0';
-			int dirNameLen = (int)strlen(entp->d_name);
+			if ( strlcat(frameworkPath, "/", PATH_MAX) >= PATH_MAX )
+				continue;
+			int dirNameLen = strlen(entp->d_name);
 			if ( dirNameLen < 11 )
 				continue;
 			if ( strcmp(&entp->d_name[dirNameLen-10], ".framework") != 0 )
@@ -1620,15 +1618,12 @@
 						if ( strncmp(&equals[-5], "_PATH", 5) == 0 ) {
 							const char* value = &equals[1];
 							const size_t keyLen = equals-keyEqualsValue;
-							// <rdar://problem/22799635> don't let malformed load command overflow stack
-							if ( keyLen < 40 ) {
-								char key[keyLen+1];
-								strncpy(key, keyEqualsValue, keyLen);
-								key[keyLen] = '\0';
-								//dyld::log("processing: %s\n", keyEqualsValue);
-								//dyld::log("mainExecutableDir: %s\n", mainExecutableDir);
-								processDyldEnvironmentVariable(key, value, mainExecutableDir);
-							}
+							char key[keyLen+1];
+							strncpy(key, keyEqualsValue, keyLen);
+							key[keyLen] = '\0';
+							//dyld::log("processing: %s\n", keyEqualsValue);
+							//dyld::log("mainExecutableDir: %s\n", mainExecutableDir);
+							processDyldEnvironmentVariable(key, value, mainExecutableDir);
 						}
 					}
 				}
@@ -4413,10 +4408,7 @@
 #if TARGET_IPHONE_SIMULATOR
 		dyld::log("dyld: warning: could not load inserted library '%s' because %s\n", path, msg);
 #else
-		if ( sProcessRequiresLibraryValidation )
-			dyld::log("dyld: warning: could not load inserted library '%s' into library validated process because %s\n", path, msg);
-		else
-			halt(dyld::mkstringf("could not load inserted library '%s' because %s\n", path, msg));
+		halt(dyld::mkstringf("could not load inserted library '%s' because %s\n", path, msg));
 #endif
 	}
 	catch (...) {
@@ -4654,8 +4646,6 @@
 					//dyld::log("dyld_sim %s mapped at %p\n", seg->segname, segAddress);
 					if ( segAddress == (void*)(-1) )
 						return 0;
-					if ( ((uintptr_t)segAddress < loadAddress) || ((uintptr_t)segAddress+seg->filesize > loadAddress+mappingSize) )
-						return 0;
 				}
 				break;
 			case LC_CODE_SIGNATURE: