Title: [86897] branches/safari-534.36-branch/Source/WebKit2

Diff

Modified: branches/safari-534.36-branch/Source/WebKit2/ChangeLog (86896 => 86897)


--- branches/safari-534.36-branch/Source/WebKit2/ChangeLog	2011-05-19 22:10:44 UTC (rev 86896)
+++ branches/safari-534.36-branch/Source/WebKit2/ChangeLog	2011-05-19 22:13:19 UTC (rev 86897)
@@ -1,5 +1,37 @@
 2011-05-19  Lucas Forschler  <[email protected]
 
+    Merged r86792.
+
+    2011-05-18  Brady Eidson  <[email protected]>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/9457633> and https://bugs.webkit.org/show_bug.cgi?id=61009
+        Processes spawned by SnowLeopard's WebProcess attempt to install WebKit2 shims.
+
+        If the WebProcess or PluginProcess forks, it shouldn't pass WebKit2 shims along to the new process
+        in the DYLD_INSERT_LIBRARIES environment variable.
+
+        Add Environment Utilities helper to strip unwanted values from an environment variable:
+        * Platform/unix/EnvironmentUtilities.cpp: Added.
+        (WebKit::EnvironmentUtilities::stripValuesEndingWithString):
+        * Platform/unix/EnvironmentUtilities.h: Added.
+        * WebKit2.xcodeproj/project.pbxproj:
+
+        Strip PluginProcessShim.dylib from DYLD_INSERT_LIBRARIES:
+        * PluginProcess/mac/PluginProcessMainMac.mm:
+        (WebKit::PluginProcessMain):
+
+        Strip WebProcessShim.dylib from DYLD_INSERT_LIBRARIES:
+        * WebProcess/mac/WebProcessMainMac.mm:
+        (WebKit::WebProcessMain):
+
+        Unprotect SnowLeopard now that it will behave and not spawn processes trying to use WebKit2 shims:
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::ProcessLauncher::launchProcess):
+
+2011-05-19  Lucas Forschler  <[email protected]
+
     Merged r86783.
     
     2011-05-18  Jon Lee  <[email protected]>

Copied: branches/safari-534.36-branch/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp (from rev 86792, trunk/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp) (0 => 86897)


--- branches/safari-534.36-branch/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp	                        (rev 0)
+++ branches/safari-534.36-branch/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp	2011-05-19 22:13:19 UTC (rev 86897)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EnvironmentUtilities.h"
+
+#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
+
+namespace WebKit {
+
+namespace EnvironmentUtilities {
+
+void stripValuesEndingWithString(const char* environmentVariable, const char* searchValue)
+{
+    ASSERT(environmentVariable);
+    ASSERT(searchValue);
+    
+    // Grab the current value of the environment variable.
+    char* environmentValue = getenv(environmentVariable);
+        
+    if (!environmentValue || environmentValue[0] == '\0')
+        return;
+
+    // Set up the strings we'll be searching for.
+    size_t searchLength = strlen(searchValue);
+    if (!searchLength)
+        return;
+
+    Vector<char> searchValueWithColonVector;
+    searchValueWithColonVector.grow(searchLength + 2);
+    char* searchValueWithColon = searchValueWithColonVector.data();
+    size_t searchLengthWithColon = searchLength + 1;
+
+    memcpy(searchValueWithColon, searchValue, searchLength);
+    searchValueWithColon[searchLength] = ':';
+    searchValueWithColon[searchLengthWithColon] = '\0';
+    
+    // Loop over environmentValueBuffer, removing any components that match the search value ending with a colon.
+    char* componentStart = environmentValue;
+    char* match = strstr(componentStart, searchValueWithColon);
+    bool foundAnyMatches = match != NULL;
+    while (match != NULL) {
+        // Update componentStart to point to the colon immediately preceding the match.
+        char* nextColon = strstr(componentStart, ":");
+        while (nextColon && nextColon < match) {
+            componentStart = nextColon;
+            nextColon = strstr(componentStart, ":");
+        }
+                
+        // Copy over everything right of the match to the current component start, and search from there again.
+        if (componentStart[0] == ':') {
+            // If componentStart points to a colon, go ahead and copy the colon over.
+            strcpy(componentStart, match + searchLength);
+        } else {
+            // Otherwise, componentStart still points to the beginning of environmentValueBuffer, so don't copy over the colon.
+            // The edge case is if the colon is the last character in the string, so "match + searchLengthWithoutColon + 1" is the
+            // null terminator of the original input, in which case this is still safe.
+            strcpy(componentStart, match + searchLengthWithColon);
+        }
+        
+        match = strstr(componentStart, searchValueWithColon);
+    }
+    
+    // Search for the value without a trailing colon, seeing if the original input ends with it.
+    match = strstr(componentStart, searchValue);
+    while (match != NULL) {
+        if (match[searchLength + 1] == '\0')
+            break;
+        match = strstr(match + 1, searchValue);
+    }
+    
+    // Since the original input ends with the search, strip out the last component.
+    if (match) {
+        // Update componentStart to point to the colon immediately preceding the match.
+        char* nextColon = strstr(componentStart, ":");
+        while (nextColon && nextColon < match) {
+            componentStart = nextColon;
+            nextColon = strstr(componentStart, ":");
+        }
+        
+        // Whether componentStart points to the original string or the last colon, putting the null terminator there will get us the desired result.
+        componentStart[0] = '\0';
+
+        foundAnyMatches = true;
+    }
+
+    // If we found no matches, don't change anything.
+    if (!foundAnyMatches)
+        return;
+
+    // If we have nothing left, just unset the variable
+    if (environmentValue[0] == '\0') {
+        unsetenv(environmentVariable);
+        return;
+    }
+    
+    setenv(environmentVariable, environmentValue, 1);
+}
+
+} // namespace EnvironmentUtilities
+
+} // namespace WebKit

Copied: branches/safari-534.36-branch/Source/WebKit2/Platform/unix/EnvironmentUtilities.h (from rev 86792, trunk/Source/WebKit2/Platform/unix/EnvironmentUtilities.h) (0 => 86897)


--- branches/safari-534.36-branch/Source/WebKit2/Platform/unix/EnvironmentUtilities.h	                        (rev 0)
+++ branches/safari-534.36-branch/Source/WebKit2/Platform/unix/EnvironmentUtilities.h	2011-05-19 22:13:19 UTC (rev 86897)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EnvironmentUtilities_h
+#define EnvironmentUtilities_h
+
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+namespace EnvironmentUtilities {
+
+void stripValuesEndingWithString(const char* environmentVariable, const char* search);
+
+} // namespace EnvironmentUtilities
+
+} // namespace WebKit
+
+#endif // #define EnvironmentUtilities_h
+

Modified: branches/safari-534.36-branch/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm (86896 => 86897)


--- branches/safari-534.36-branch/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm	2011-05-19 22:10:44 UTC (rev 86896)
+++ branches/safari-534.36-branch/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm	2011-05-19 22:13:19 UTC (rev 86897)
@@ -29,6 +29,7 @@
 #if ENABLE(PLUGIN_PROCESS)
 
 #import "CommandLine.h"
+#import "EnvironmentUtilities.h"
 #import "NetscapePluginModule.h"
 #import "PluginProcess.h"
 #import "RunLoop.h"
@@ -51,9 +52,9 @@
 
 int PluginProcessMain(const CommandLine& commandLine)
 {
-    // Unset DYLD_INSERT_LIBRARIES. We don't want our plug-in process shim to be loaded 
-    // by any child processes that the plug-in may launch.
-    unsetenv("DYLD_INSERT_LIBRARIES");
+    // Remove the PluginProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes 
+    // spawned by the PluginProcess don't try to insert the shim and crash.
+    EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/PluginProcessShim.dylib");
 
     // Check if we're being spawned to write a MIME type preferences file.
     String pluginPath = commandLine["createPluginMIMETypesPreferences"];

Modified: branches/safari-534.36-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (86896 => 86897)


--- branches/safari-534.36-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2011-05-19 22:10:44 UTC (rev 86896)
+++ branches/safari-534.36-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2011-05-19 22:13:19 UTC (rev 86897)
@@ -362,6 +362,8 @@
 		51ACBB82127A8BAD00D203B9 /* WebContextMenuProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ACBB81127A8BAD00D203B9 /* WebContextMenuProxy.h */; };
 		51ACBBA0127A8F2C00D203B9 /* WebContextMenuProxyMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ACBB9E127A8F2C00D203B9 /* WebContextMenuProxyMac.h */; };
 		51ACBBA1127A8F2C00D203B9 /* WebContextMenuProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */; };
+		51B15A8413843A3900321AD8 /* EnvironmentUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B15A8213843A3900321AD8 /* EnvironmentUtilities.cpp */; };
+		51B15A8513843A3900321AD8 /* EnvironmentUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B15A8313843A3900321AD8 /* EnvironmentUtilities.h */; };
 		51B3005012529D0E000B5CA0 /* WebBackForwardListCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B3004E12529D0E000B5CA0 /* WebBackForwardListCF.cpp */; };
 		51B3005112529D0E000B5CA0 /* WebPageProxyCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B3004F12529D0E000B5CA0 /* WebPageProxyCF.cpp */; };
 		51C4032C136749D800DC972D /* AuthenticationManager.mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51C4032B136749D800DC972D /* AuthenticationManager.mac.mm */; };
@@ -1290,6 +1292,8 @@
 		51ACBB81127A8BAD00D203B9 /* WebContextMenuProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenuProxy.h; sourceTree = "<group>"; };
 		51ACBB9E127A8F2C00D203B9 /* WebContextMenuProxyMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMenuProxyMac.h; sourceTree = "<group>"; };
 		51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContextMenuProxyMac.mm; sourceTree = "<group>"; };
+		51B15A8213843A3900321AD8 /* EnvironmentUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = EnvironmentUtilities.cpp; path = unix/EnvironmentUtilities.cpp; sourceTree = "<group>"; };
+		51B15A8313843A3900321AD8 /* EnvironmentUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EnvironmentUtilities.h; path = unix/EnvironmentUtilities.h; sourceTree = "<group>"; };
 		51B3004E12529D0E000B5CA0 /* WebBackForwardListCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebBackForwardListCF.cpp; path = cf/WebBackForwardListCF.cpp; sourceTree = "<group>"; };
 		51B3004F12529D0E000B5CA0 /* WebPageProxyCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebPageProxyCF.cpp; path = cf/WebPageProxyCF.cpp; sourceTree = "<group>"; };
 		51C4032B136749D800DC972D /* AuthenticationManager.mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AuthenticationManager.mac.mm; path = mac/AuthenticationManager.mac.mm; sourceTree = "<group>"; };
@@ -2426,6 +2430,15 @@
 			name = KeyValueStorage;
 			sourceTree = "<group>";
 		};
+		51B15A7D138439B200321AD8 /* unix */ = {
+			isa = PBXGroup;
+			children = (
+				51B15A8213843A3900321AD8 /* EnvironmentUtilities.cpp */,
+				51B15A8313843A3900321AD8 /* EnvironmentUtilities.h */,
+			);
+			name = unix;
+			sourceTree = "<group>";
+		};
 		51B3004D12529CF5000B5CA0 /* cf */ = {
 			isa = PBXGroup;
 			children = (
@@ -3017,6 +3030,7 @@
 				1AA2E51A12E4C05600BC4966 /* cg */,
 				1AB5A1BA10E021D30040F6CF /* CoreIPC */,
 				1A7E814E1152D2240003695B /* mac */,
+				51B15A7D138439B200321AD8 /* unix */,
 				51A7F2F4125BF8D4008AEB1D /* Logging.cpp */,
 				51A7F2F2125BF820008AEB1D /* Logging.h */,
 				C0E3AA451209E2BA00A49D01 /* Module.cpp */,
@@ -3795,6 +3809,7 @@
 				1A179780137EE82C00F97D45 /* PluginCreationParameters.h in Headers */,
 				51D130541382EAC000351EDD /* SecItemRequestData.h in Headers */,
 				51D130561382EAC000351EDD /* SecItemResponseData.h in Headers */,
+				51B15A8513843A3900321AD8 /* EnvironmentUtilities.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -4461,6 +4476,7 @@
 				51D130531382EAC000351EDD /* SecItemRequestData.cpp in Sources */,
 				51D130551382EAC000351EDD /* SecItemResponseData.cpp in Sources */,
 				51D130581382F10500351EDD /* WebProcessProxyMac.mm in Sources */,
+				51B15A8413843A3900321AD8 /* EnvironmentUtilities.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: branches/safari-534.36-branch/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm (86896 => 86897)


--- branches/safari-534.36-branch/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm	2011-05-19 22:10:44 UTC (rev 86896)
+++ branches/safari-534.36-branch/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm	2011-05-19 22:13:19 UTC (rev 86897)
@@ -27,6 +27,7 @@
 #import "WebProcessMain.h"
 
 #import "CommandLine.h"
+#import "EnvironmentUtilities.h"
 #import "RunLoop.h"
 #import "WebProcess.h"
 #import "WebSystemInterface.h"
@@ -42,6 +43,7 @@
 #import <wtf/RetainPtr.h>
 #import <wtf/Threading.h>
 #import <wtf/text/CString.h>
+#import <wtf/text/StringBuilder.h>
 
 // FIXME: We should be doing this another way.
 extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
@@ -58,6 +60,12 @@
 
 int WebProcessMain(const CommandLine& commandLine)
 {
+#ifdef BUILDING_ON_SNOWLEOPARD
+    // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by
+    // the WebProcess don't try to insert the shim and crash.
+    EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/WebProcessShim.dylib");
+#endif
+
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
     String serviceName = commandLine["servicename"];
@@ -90,10 +98,8 @@
     WTF::initializeMainThread();
     RunLoop::initializeMainRunLoop();
 
-#ifndef BUILDING_ON_SNOW_LEOPARD
     // Initialize the shim.
     WebProcess::shared().initializeShim();
-#endif
 
     // Create the connection.
     WebProcess::shared().initialize(serverPort, RunLoop::main());
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to