From 65e61f3c88388d4a2ed88bcc9a2cb5ba63fd8afa Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 20 Mar 2023 06:03:51 -0700 Subject: [PATCH] Enable Address and Undefined Behavior Sanitizers (#36443) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This change does two things: 1) Moves RNTester on iOS to use an `.xctestplan` to configure its tests. This moves the test configuration out of the `.xcscheme` file, and into a new json file that Xcode likes. It also allows you to run the same tests multiple times with different configurations. This was done by clicking the focused button below. ![image](https://user-images.githubusercontent.com/6722175/224447314-49d460e9-d2d6-4ec9-9767-64c2a1c449c0.png) Note: this is partially me upstreaming a change from React Native macOS (https://github.com/microsoft/react-native-macos/pull/190/), though at some point our Xcode project got messed up and we were no longer referencing them ��. 2) Enables Address Sanitizer and Udefined Behavior Sanitizer through the xctestplan This should help catch some extra vulnerabilities should they ever show up while our tests run. Notably, I did not _also_ add a configuration to run Thread Sanitizer, because tests start failing with that enabled 😅. ## Changelog: [IOS] [SECURITY] - Enable Address and Undefined Behavior Sanitizers on RNTester Pull Request resolved: https://github.com/facebook/react-native/pull/36443 Test Plan: CI should pass Reviewed By: cortinico Differential Revision: D44213517 Pulled By: cipolleschi fbshipit-source-id: 0646174c4b416413a563e8178aa2cfca230b5e66 --- .../NativeAnimation/RCTAnimationUtils.h | 4 +- .../NativeAnimation/RCTAnimationUtils.m | 8 ++-- .../rn-tester/RNTester/RNTester.xctestplan | 46 +++++++++++++++++++ .../RNTesterPods.xcodeproj/project.pbxproj | 2 + .../xcshareddata/xcschemes/RNTester.xcscheme | 46 +++---------------- 5 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 packages/rn-tester/RNTester/RNTester.xctestplan diff --git a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h index 338a88b4832..77152f4a577 100644 --- a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h +++ b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h @@ -32,11 +32,11 @@ RCT_EXTERN CGFloat RCTInterpolateValueInRange( NSString *extrapolateLeft, NSString *extrapolateRight); -RCT_EXTERN int32_t +RCT_EXTERN uint32_t RCTInterpolateColorInRange(CGFloat value, NSArray *inputRange, NSArray *outputRange); // Represents a color as a int32_t. RGB components are assumed to be in [0-255] range and alpha in [0-1] range -RCT_EXTERN int32_t RCTColorFromComponents(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); +RCT_EXTERN uint32_t RCTColorFromComponents(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); /** * Coefficient to slow down animations, respects the ios diff --git a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.m b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.m index 22ee2bc9080..f628826c660 100644 --- a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.m +++ b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.m @@ -84,7 +84,7 @@ CGFloat RCTInterpolateValueInRange( return RCTInterpolateValue(value, inputMin, inputMax, outputMin, outputMax, extrapolateLeft, extrapolateRight); } -int32_t RCTInterpolateColorInRange(CGFloat value, NSArray *inputRange, NSArray *outputRange) +uint32_t RCTInterpolateColorInRange(CGFloat value, NSArray *inputRange, NSArray *outputRange) { NSUInteger rangeIndex = RCTFindIndexOfNearestValue(value, inputRange); CGFloat inputMin = inputRange[rangeIndex].doubleValue; @@ -102,10 +102,10 @@ int32_t RCTInterpolateColorInRange(CGFloat value, NSArray *inputRang alphaMin + (value - inputMin) * (alphaMax - alphaMin) / (inputMax - inputMin)); } -int32_t RCTColorFromComponents(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) +uint32_t RCTColorFromComponents(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) { - return ((int)round(alpha * 255) & 0xFF) << 24 | ((int)round(red) & 0xFF) << 16 | ((int)round(green) & 0xFF) << 8 | - ((int)round(blue) & 0xFF); + return ((uint32_t)round(alpha * 255) & 0xFF) << 24 | ((uint32_t)round(red) & 0xFF) << 16 | + ((uint32_t)round(green) & 0xFF) << 8 | ((uint32_t)round(blue) & 0xFF); } #if TARGET_IPHONE_SIMULATOR diff --git a/packages/rn-tester/RNTester/RNTester.xctestplan b/packages/rn-tester/RNTester/RNTester.xctestplan new file mode 100644 index 00000000000..147173b22f8 --- /dev/null +++ b/packages/rn-tester/RNTester/RNTester.xctestplan @@ -0,0 +1,46 @@ +{ + "configurations" : [ + { + "id" : "1D5134C7-450A-44B6-A8B1-13CD24FD50B9", + "name" : "Address Sanitizer", + "options" : { + "addressSanitizer" : { + "detectStackUseAfterReturn" : true, + "enabled" : true + } + } + } + ], + "defaultOptions" : { + "codeCoverage" : false, + "environmentVariableEntries" : [ + { + "key" : "CI_USE_PACKAGER", + "value" : "1" + } + ], + "targetForVariableExpansion" : { + "containerPath" : "container:RNTesterPods.xcodeproj", + "identifier" : "13B07F861A680F5B00A75B9A", + "name" : "RNTester" + }, + "undefinedBehaviorSanitizerEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:RNTesterPods.xcodeproj", + "identifier" : "E7DB215222B2F332005AC45F", + "name" : "RNTesterIntegrationTests" + } + }, + { + "target" : { + "containerPath" : "container:RNTesterPods.xcodeproj", + "identifier" : "E7DB209E22B2BA84005AC45F", + "name" : "RNTesterUnitTests" + } + } + ], + "version" : 1 +} diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index dd082a9a0a8..f43cd892f01 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -101,6 +101,7 @@ 6144DEEE56C6C17B301A90E4 /* libPods-RNTesterUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTesterUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 7FC437025B5EE3899315628B /* Pods-RNTester.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTester.release.xcconfig"; path = "Target Support Files/Pods-RNTester/Pods-RNTester.release.xcconfig"; sourceTree = ""; }; 8145AE05241172D900A3F8DA /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = RNTester/LaunchScreen.storyboard; sourceTree = ""; }; + AC474BFB29BBD4A1002BDAED /* RNTester.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = RNTester.xctestplan; path = RNTester/RNTester.xctestplan; sourceTree = ""; }; B8219B8DAB1CDD38543E30A4 /* Pods-RNTesterUnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTesterUnitTests.release.xcconfig"; path = "Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests.release.xcconfig"; sourceTree = ""; }; BD6F35F6C79ACF7496CBC337 /* Pods-RNTesterIntegrationTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTesterIntegrationTests.release.xcconfig"; path = "Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests.release.xcconfig"; sourceTree = ""; }; C4CEC47A71A2AEE236833CDF /* Pods-RNTesterUnitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTesterUnitTests.debug.xcconfig"; path = "Target Support Files/Pods-RNTesterUnitTests/Pods-RNTesterUnitTests.debug.xcconfig"; sourceTree = ""; }; @@ -225,6 +226,7 @@ isa = PBXGroup; children = ( 0CC3BE1A25DDB68A0033CAEB /* RNTester.entitlements */, + AC474BFB29BBD4A1002BDAED /* RNTester.xctestplan */, E771AEEA22B44E3100EA1189 /* Info.plist */, 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 5C60EB1B226440DB0018C04F /* AppDelegate.mm */, diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/xcshareddata/xcschemes/RNTester.xcscheme b/packages/rn-tester/RNTesterPods.xcodeproj/xcshareddata/xcschemes/RNTester.xcscheme index ec1fa4d2858..417f850440e 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/xcshareddata/xcschemes/RNTester.xcscheme +++ b/packages/rn-tester/RNTesterPods.xcodeproj/xcshareddata/xcschemes/RNTester.xcscheme @@ -1,7 +1,7 @@ + version = "1.7"> @@ -27,44 +27,12 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "NO"> - - - - - - - - - - - - - - - - - - + + + +