Integer overflow check in memory allocation #213
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Synopsis
The copy of RSSwizzle embedded in TrustKit uses an unchecked outside value to allocate memory. The PR adds integer overflow protection to the memory allocation size.
Attack Details
This code was flagged by automated static security scanners at Yahoo. The vulnerability details are https://cwe.mitre.org/data/definitions/190.html
The scanner message:
Proposed Fix
Added a simple integer overflow check to the code:
if (strlen(x) > strlen(..)+2) {...}
. When this case is true, the Swizzling is aborted.Impact
There is no realistic failure path that doesn't impact the library. In the event of integer overflow in the objective-c type specifier, I added
return NO
, effectively declining to swizzle the method. The alternative is to allow the integer overflow, which will almost certainly crash the containing program. I would say that the impact of having this fix is "less severe" than not having it.