Skip to content

Commit

Permalink
Enable Address and Undefined Behavior Sanitizers (#36443)
Browse files Browse the repository at this point in the history
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 (microsoft#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: #36443

Test Plan: CI should pass

Reviewed By: cortinico

Differential Revision: D44213517

Pulled By: cipolleschi

fbshipit-source-id: 0646174c4b416413a563e8178aa2cfca230b5e66
  • Loading branch information
Saadnajmi authored and facebook-github-bot committed Mar 20, 2023
1 parent cd65a32 commit 65e61f3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ RCT_EXTERN CGFloat RCTInterpolateValueInRange(
NSString *extrapolateLeft,
NSString *extrapolateRight);

RCT_EXTERN int32_t
RCT_EXTERN uint32_t
RCTInterpolateColorInRange(CGFloat value, NSArray<NSNumber *> *inputRange, NSArray<UIColor *> *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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ CGFloat RCTInterpolateValueInRange(
return RCTInterpolateValue(value, inputMin, inputMax, outputMin, outputMax, extrapolateLeft, extrapolateRight);
}

int32_t RCTInterpolateColorInRange(CGFloat value, NSArray<NSNumber *> *inputRange, NSArray<UIColor *> *outputRange)
uint32_t RCTInterpolateColorInRange(CGFloat value, NSArray<NSNumber *> *inputRange, NSArray<UIColor *> *outputRange)
{
NSUInteger rangeIndex = RCTFindIndexOfNearestValue(value, inputRange);
CGFloat inputMin = inputRange[rangeIndex].doubleValue;
Expand All @@ -102,10 +102,10 @@ int32_t RCTInterpolateColorInRange(CGFloat value, NSArray<NSNumber *> *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
Expand Down
46 changes: 46 additions & 0 deletions packages/rn-tester/RNTester/RNTester.xctestplan
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
8145AE05241172D900A3F8DA /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = RNTester/LaunchScreen.storyboard; sourceTree = "<group>"; };
AC474BFB29BBD4A1002BDAED /* RNTester.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = RNTester.xctestplan; path = RNTester/RNTester.xctestplan; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -225,6 +226,7 @@
isa = PBXGroup;
children = (
0CC3BE1A25DDB68A0033CAEB /* RNTester.entitlements */,
AC474BFB29BBD4A1002BDAED /* RNTester.xctestplan */,
E771AEEA22B44E3100EA1189 /* Info.plist */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
5C60EB1B226440DB0018C04F /* AppDelegate.mm */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1210"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -27,44 +27,12 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "NO">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "RNTester.app"
BlueprintName = "RNTester"
ReferencedContainer = "container:RNTesterPods.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "CI_USE_PACKAGER"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E7DB215222B2F332005AC45F"
BuildableName = "RNTesterIntegrationTests.xctest"
BlueprintName = "RNTesterIntegrationTests"
ReferencedContainer = "container:RNTesterPods.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E7DB209E22B2BA84005AC45F"
BuildableName = "RNTesterUnitTests.xctest"
BlueprintName = "RNTesterUnitTests"
ReferencedContainer = "container:RNTesterPods.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<TestPlans>
<TestPlanReference
reference = "container:RNTester/RNTester.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down

0 comments on commit 65e61f3

Please sign in to comment.