Skip to content

Commit

Permalink
fix: crash when insert nil value into a dictionary (#30066)
Browse files Browse the repository at this point in the history
Summary:
This PR attempts to fix issue #28278 and #29525

On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value.

```
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
```

This PR is following the suggestion of this: #28278 (comment) and it replaces the values of any property if it is nil. In detail:
- it converts `error` to empty NSString if the original value is nil
- it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil

## Changelog

[iOS] [Fixed] - A crash in WebSocket module

Pull Request resolved: #30066

Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

Reviewed By: shergin

Differential Revision: D24241147

Pulled By: sammy-SC

fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
  • Loading branch information
marksinkovics authored and facebook-github-bot committed Oct 12, 2020
1 parent 6685aba commit 748aa13
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion React/CoreModules/RCTWebSocketModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
NSNumber *socketID = [webSocket reactTag];
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
[self sendEventWithName:@"websocketFailed" body:@{@"message" : error.localizedDescription, @"id" : socketID}];
NSDictionary *body =
@{@"message" : error.localizedDescription ?: @"Undefined, error is nil", @"id" : socketID ?: @(-1)};
[self sendEventWithName:@"websocketFailed" body:body];
}

- (void)webSocket:(RCTSRWebSocket *)webSocket
Expand Down

0 comments on commit 748aa13

Please sign in to comment.