Changeset 215521 in webkit
- Timestamp:
- Apr 19, 2017 11:17:02 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r215512 r215521 1 2017-04-19 David Kilzer <ddkilzer@apple.com> 2 3 Stop using strcpy() in WebKit::EnvironmentUtilities::stripValuesEndingWithString() 4 <https://webkit.org/b/170994> 5 <rdar://problem/29889932> 6 7 Reviewed by Brent Fulgham. 8 9 * Platform/unix/EnvironmentUtilities.cpp: 10 (WebKit::EnvironmentUtilities::stripValuesEndingWithString): 11 Switch from using strcpy() to strlcpy(). Also switch from using 12 strstr() to strnstr(). 13 * Platform/unix/EnvironmentUtilities.h: Switch to #pragma once. 14 (WebKit::EnvironmentUtilities::stripValuesEndingWithString): 15 Export function for testing. 16 * WebKit2.xcodeproj/project.pbxproj: 17 (EnvironmentUtilitiesTest.h): Make header private for testing. 18 1 19 2017-04-19 Eric Carlson <eric.carlson@apple.com> 2 20 -
trunk/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp
r182364 r215521 40 40 // Grab the current value of the environment variable. 41 41 char* environmentValue = getenv(environmentVariable); 42 42 43 43 if (!environmentValue || environmentValue[0] == '\0') 44 44 return; 45 46 const size_t environmentValueLength = strlen(environmentValue); 47 const size_t environmentValueBufferLength = environmentValueLength + 1; 45 48 46 49 // Set up the strings we'll be searching for. … … 60 63 // Loop over environmentValueBuffer, removing any components that match the search value ending with a colon. 61 64 char* componentStart = environmentValue; 62 char* match = str str(componentStart, searchValueWithColon);65 char* match = strnstr(componentStart, searchValueWithColon, environmentValueLength - static_cast<size_t>(componentStart - environmentValue)); 63 66 bool foundAnyMatches = match != NULL; 64 67 while (match != NULL) { 65 68 // Update componentStart to point to the colon immediately preceding the match. 66 char* nextColon = str str(componentStart, ":");69 char* nextColon = strnstr(componentStart, ":", environmentValueLength - static_cast<size_t>(componentStart - environmentValue)); 67 70 while (nextColon && nextColon < match) { 68 71 componentStart = nextColon; 69 nextColon = str str(componentStart + 1, ":");72 nextColon = strnstr(componentStart + 1, ":", environmentValueLength - static_cast<size_t>(componentStart + 1 - environmentValue)); 70 73 } 71 74 75 RELEASE_ASSERT(componentStart >= environmentValue); 76 size_t environmentValueOffset = static_cast<size_t>(componentStart - environmentValue); 77 RELEASE_ASSERT(environmentValueOffset < environmentValueBufferLength); 78 72 79 // Copy over everything right of the match to the current component start, and search from there again. 73 80 if (componentStart[0] == ':') { 74 81 // If componentStart points to a colon, copy the colon over. 75 str cpy(componentStart, match + searchLength);82 strlcpy(componentStart, match + searchLength, environmentValueBufferLength - environmentValueOffset); 76 83 } else { 77 84 // Otherwise, componentStart still points to the beginning of environmentValueBuffer, so don't copy over the colon. 78 85 // The edge case is if the colon is the last character in the string, so "match + searchLengthWithoutColon + 1" is the 79 86 // null terminator of the original input, in which case this is still safe. 80 str cpy(componentStart, match + searchLengthWithColon);87 strlcpy(componentStart, match + searchLengthWithColon, environmentValueBufferLength - environmentValueOffset); 81 88 } 82 89 83 match = str str(componentStart, searchValueWithColon);90 match = strnstr(componentStart, searchValueWithColon, environmentValueLength - static_cast<size_t>(componentStart - environmentValue)); 84 91 } 85 92 86 93 // Search for the value without a trailing colon, seeing if the original input ends with it. 87 match = str str(componentStart, searchValue);94 match = strnstr(componentStart, searchValue, environmentValueLength - static_cast<size_t>(componentStart - environmentValue)); 88 95 while (match != NULL) { 89 96 if (match[searchLength] == '\0') 90 97 break; 91 match = str str(match + 1, searchValue);98 match = strnstr(match + 1, searchValue, environmentValueLength - static_cast<size_t>(match + 1 - environmentValue)); 92 99 } 93 100 … … 95 102 if (match) { 96 103 // Update componentStart to point to the colon immediately preceding the match. 97 char* nextColon = str str(componentStart, ":");104 char* nextColon = strnstr(componentStart, ":", environmentValueLength - static_cast<size_t>(componentStart - environmentValue)); 98 105 while (nextColon && nextColon < match) { 99 106 componentStart = nextColon; 100 nextColon = str str(componentStart + 1, ":");107 nextColon = strnstr(componentStart + 1, ":", environmentValueLength - static_cast<size_t>(componentStart + 1 - environmentValue)); 101 108 } 102 109 -
trunk/Source/WebKit2/Platform/unix/EnvironmentUtilities.h
r95901 r215521 24 24 */ 25 25 26 #ifndef EnvironmentUtilities_h 27 #define EnvironmentUtilities_h 26 #pragma once 28 27 28 #include "WKDeclarationSpecifiers.h" 29 29 #include <wtf/text/WTFString.h> 30 30 … … 33 33 namespace EnvironmentUtilities { 34 34 35 void stripValuesEndingWithString(const char* environmentVariable, const char* search);35 WK_EXPORT void stripValuesEndingWithString(const char* environmentVariable, const char* search); 36 36 37 37 } // namespace EnvironmentUtilities 38 38 39 39 } // namespace WebKit 40 41 #endif // #define EnvironmentUtilities_h42 -
trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
r215488 r215521 1043 1043 51ACBBA1127A8F2C00D203B9 /* WebContextMenuProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */; }; 1044 1044 51B15A8413843A3900321AD8 /* EnvironmentUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B15A8213843A3900321AD8 /* EnvironmentUtilities.cpp */; }; 1045 51B15A8513843A3900321AD8 /* EnvironmentUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B15A8313843A3900321AD8 /* EnvironmentUtilities.h */; };1045 51B15A8513843A3900321AD8 /* EnvironmentUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B15A8313843A3900321AD8 /* EnvironmentUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1046 1046 51C0C9741DDD76000032CAD3 /* IconLoadingDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 51C0C9721DDD74F00032CAD3 /* IconLoadingDelegate.h */; }; 1047 1047 51C0C9751DDD76030032CAD3 /* IconLoadingDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51C0C9731DDD74F00032CAD3 /* IconLoadingDelegate.mm */; }; -
trunk/Tools/ChangeLog
r215519 r215521 1 2017-04-19 David Kilzer <ddkilzer@apple.com> 2 3 Stop using strcpy() in WebKit::EnvironmentUtilities::stripValuesEndingWithString() 4 <https://webkit.org/b/170994> 5 <rdar://problem/29889932> 6 7 Reviewed by Brent Fulgham. 8 9 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 10 (EnvironmentUtilitiesTest.cpp): Add to TestWebKitAPILibrary 11 target. 12 * TestWebKitAPI/Tests/WebKit2/EnvironmentUtilitiesTest.cpp: Add. 13 (TestWebKitAPI::strip): Helper method to set/get environment 14 variable for testing. 15 (TestWebKitAPI::WebKit2_StripValuesEndingWithString_Test): Add 16 tests. 17 1 18 2017-04-19 JF Bastien <jfbastien@apple.com> 2 19 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r215424 r215521 124 124 37FB72971DB2E82F00E41BE4 /* ContextMenuDefaultItemsHaveTags.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37FB72951DB2E82F00E41BE4 /* ContextMenuDefaultItemsHaveTags.mm */; }; 125 125 3FBD1B4A1D3D66AB00E6D6FA /* FullscreenLayoutConstraints.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 3FBD1B491D39D1DB00E6D6FA /* FullscreenLayoutConstraints.html */; }; 126 448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */; }; 126 127 46397B951DC2C850009A78AE /* DOMNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46397B941DC2C850009A78AE /* DOMNode.mm */; }; 127 128 46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */; }; … … 1040 1041 440A1D3814A0103A008A66F2 /* URL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URL.cpp; sourceTree = "<group>"; }; 1041 1042 442BBF681C91CAD90017087F /* RefLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefLogger.cpp; sourceTree = "<group>"; }; 1043 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnvironmentUtilitiesTest.cpp; sourceTree = "<group>"; }; 1042 1044 44A622C114A0E2B60048515B /* WTFStringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFStringUtilities.h; sourceTree = "<group>"; }; 1043 1045 46397B941DC2C850009A78AE /* DOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMNode.mm; sourceTree = "<group>"; }; … … 2022 2024 C045F9441385C2E900C0F3CD /* DownloadDecideDestinationCrash.cpp */, 2023 2025 07492B3A1DF8AE2D00633DE1 /* EnumerateMediaDevices.cpp */, 2026 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */, 2024 2027 75F3133F18C171B70041CAEC /* EphemeralSessionPushStateNoHistoryCallback.cpp */, 2025 2028 1A5FEFDC1270E2A3000E2921 /* EvaluateJavaScript.cpp */, … … 2811 2814 7CCE7EBF1A411A7E00447C4C /* ElementAtPointInWebFrame.mm in Sources */, 2812 2815 07492B3B1DF8B14C00633DE1 /* EnumerateMediaDevices.cpp in Sources */, 2816 448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */, 2813 2817 7CCE7EEF1A411AE600447C4C /* EphemeralSessionPushStateNoHistoryCallback.cpp in Sources */, 2814 2818 7CCE7EF01A411AE600447C4C /* EvaluateJavaScript.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.