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

Fix unrecognized selector crash when adding metadata #429

Closed
wants to merge 3 commits into from

Conversation

fractalwrench
Copy link
Contributor

Goal

Prevents an unrecognized selector crash when adding metadata to a report in a beforeSend block.

The root cause of this bug is that an NSDictionary can be a tab value in the metadata property, whereas we assume that this is always an NSMutableDictionary. Adding a new attribute therefore triggers a crash, because bugsnag-cocoa attempts to mutate an immutable dictionary here: https://github.com/bugsnag/bugsnag-cocoa/blob/master/Source/BugsnagCrashReport.m#L396

Setting a user then starting a session provides one way to manifest this bug, as this uses an NSDictionary rather than NSMutableDictionary when deserializing crash reports. If an attribute is then added to an existing tab (e.g. app, device, user) in a beforeSend callback, this will crash the app: https://github.com/bugsnag/bugsnag-cocoa/blob/master/Source/BugsnagCrashReport.m#L259

private func setUpBugsnag() {
    let configuration = BugsnagConfiguration()
    configuration.add(beforeSend: self.willSendReport)
    configuration.setUser("my-user-123", withName: nil, andEmail: nil)
    Bugsnag.start(with: configuration)
    Bugsnag.startSession()
}

private func willSendReport(_ rawData: [AnyHashable: Any], report: BugsnagCrashReport) -> Bool {
    report.addMetadata(["foo": "bar"], toTabWithName: "user")
    report.addAttribute("session", withValue: "foobar", toTabWithName: "user")
    return true
}

Changeset

Converted the tab value to an NSMutableDictionary if it was not already of this type.

Tests

Manually verified that a report is now sent to the dashboard with the example case.

@rebello95
Copy link

Thanks for fixing! Can we add a unit test for this as well to validate it no longer crashes and prevent similar regressions?

@kattrali
Copy link
Contributor

kattrali commented Nov 4, 2019

Merged #430 with some changes from this PR as well. Thanks!

@kattrali kattrali closed this Nov 4, 2019
@kattrali kattrali deleted the add-attr-fix branch November 4, 2019 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants