Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Exception Handling | Input Validation - RCTAlertController - RCTDevLoadingView #35689

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion React/CoreModules/RCTAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ @implementation RCTAlertController
- (UIWindow *)alertWindow
{
if (_alertWindow == nil) {
_alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds];
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
if (keyWindow) {
_alertWindow = [[UIWindow alloc] initWithFrame:keyWindow.bounds];
_alertWindow.rootViewController = [UIViewController new];
_alertWindow.windowLevel = UIWindowLevelAlert + 1;
} else {
// keyWindow is nil, so we cannot create and initialize _alertWindow
NSLog(@"Unable to create alert window: keyWindow is nil");
}
}

return _alertWindow;
}

Expand Down
14 changes: 14 additions & 0 deletions React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
return;
}

// Input validation
if (message == nil || [message isEqualToString:@""]) {
NSLog(@"Error: message cannot be nil or empty");
return;
}
if (color == nil) {
NSLog(@"Error: color cannot be nil");
return;
}
if (backgroundColor == nil) {
NSLog(@"Error: backgroundColor cannot be nil");
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
self->_showDate = [NSDate date];
if (!self->_window && !RCTRunningInTestEnvironment()) {
Expand Down