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: Make metadata tabs always mutable #430

Merged
merged 2 commits into from
Nov 4, 2019
Merged

Conversation

snmaynard
Copy link
Contributor

This PR addresses an issue whereby a tab within metadata can be an NSDictionary rather than an NSMutableDictionary, and an exception can be generated in a beforeSend callback, preventing the report being sent. The dictionaries in metadata can be immutable because within the constructor of a report we don't use the property setter or call through to BSGSanitizeDict which will ensure the dictionary is mutable. See https://github.com/bugsnag/bugsnag-cocoa/blob/master/Source/BugsnagCrashReport.m#L280 for an example.

The fix I have gone for here is to make a mutableCopy of the tab within the addAttribute:withValue:toTabWithName function. We could also add some calls to BSGSanitizeDict inside the constructor when initially setting the metadata value, which will ensure the dictionary is mutable, but I don't know the context of why that is not already there. Maybe @kattrali had a reason to avoid the setter when constructing the class. We could add the santize call also if we think that is a good idea for a belt and braces approach.

I have also added a try-catch to the execution of each beforeSend callback to ensure that if they throw an exception, the result is just that the beforeSend don't execute, rather than preventing delivery of the reports.

It is worth pointing out that I believeaddMetadata:toTabWithName: was not affected by this issue and so is unchanged.

The tests have also been paired back to be the bare minimum to reproduce the issue and verify the code change fixes it. This PR is an alternative to #429.

@snmaynard snmaynard force-pushed the fix-immutable-dict-metadata branch from b56950f to ff1cd11 Compare November 1, 2019 23:19
@kattrali kattrali changed the title Fix potential issue setting metadata in beforeSend callbacks fix: Make metadata tabs always mutable Nov 4, 2019
@kattrali kattrali merged commit 63f656c into master Nov 4, 2019
@kattrali kattrali deleted the fix-immutable-dict-metadata 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.

2 participants