Skip to content

Commit e9c7ebf

Browse files
nicklockwoodfacebook-github-bot-5
authored andcommitted
Ensure bad JS does not crash the app
Summary: public We have code in place to ensure that a red box is displayed when bad arguments are sent to exported methods, however the methods were still being called with nil values for those arguments, resulting in crashes if the method wasn't set up to handle nil gracefully. This diff ensures that methods will not be called if any of the argument conversion functions log an error. It also explicitly checks for nil output for arguments that are marked as nonnull. Reviewed By: javache, tadeuzagallo Differential Revision: D2580658 fb-gh-sync-id: aad6be758ea19f9b4521f3f9f0407bf672c0a2dd
1 parent b86a6e3 commit e9c7ebf

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

React/Base/RCTModuleMethod.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,23 @@ - (void)processMethodSignature
363363
if (nullability == RCTNonnullable) {
364364
RCTArgumentBlock oldBlock = argumentBlocks[i - 2];
365365
argumentBlocks[i - 2] = ^(RCTBridge *bridge, NSUInteger index, id json) {
366-
if (json == nil) {
367-
RCTLogArgumentError(weakSelf, index, typeName, "must not be null");
368-
return NO;
369-
} else {
370-
return oldBlock(bridge, index, json);
366+
if (json != nil) {
367+
if (!oldBlock(bridge, index, json)) {
368+
return NO;
369+
}
370+
if (isNullableType) {
371+
// Check converted value wasn't null either, as method probably
372+
// won't gracefully handle a nil vallue for a nonull argument
373+
void *value;
374+
[invocation getArgument:&value atIndex:index + 2];
375+
if (value == NULL) {
376+
return NO;
377+
}
378+
}
379+
return YES;
371380
}
381+
RCTLogArgumentError(weakSelf, index, typeName, "must not be null");
382+
return NO;
372383
};
373384
}
374385
}

0 commit comments

Comments
 (0)