Skip to content

Commit

Permalink
Fix possible Ti.Buffer / Ti.Blob leaks for edge-cases, wrap iOS 12 pr…
Browse files Browse the repository at this point in the history
…oxy-API's (not required but looks more clean)
  • Loading branch information
hansemannn committed Aug 7, 2018
1 parent 8cbf3b2 commit a56529c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,12 @@ - (id)scheduleLocalNotification:(id)args
id badge = [args objectForKey:@"badge"];
id userInfo = [args objectForKey:@"userInfo"];
id sound = [args objectForKey:@"sound"];
id timezone = [args objectForKey:@"timezone"];
#if IS_XCODE_10
id summaryArgument = [args objectForKey:@"summaryArgument"];
id summaryArgumentCount = [args objectForKey:@"summaryArgumentCount"];
id threadIdentifier = [args objectForKey:@"threadIdentifier"];
id timezone = [args objectForKey:@"timezone"];
#endif

// Construct a new local notification proxy from our current context
TiAppiOSLocalNotificationProxy *notification = [[[TiAppiOSLocalNotificationProxy alloc] _initWithPageContext:[self executionContext]] autorelease];
Expand Down
4 changes: 3 additions & 1 deletion iphone/Classes/TiAppiOSUserNotificationCategoryProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ - (void)_initWithProperties:(NSDictionary *)properties
NSArray *actionsForMinimalContext = [properties valueForKey:@"actionsForMinimalContext"];
NSArray *intentIdentifiers = [properties valueForKey:@"intentIdentifiers"] ?: @[];
NSString *hiddenPreviewsBodyPlaceholder = [properties valueForKey:@"hiddenPreviewsBodyPlaceholder"];
NSString *categorySummaryFormat = [properties valueForKey:@"categorySummaryFormat"];
UNNotificationCategoryOptions options = [self categoryOptionsFromArray:[properties valueForKey:@"options"] ?: @[]];
#if IS_XCODE_10
NSString *categorySummaryFormat = [properties valueForKey:@"categorySummaryFormat"];
#endif

NSMutableArray *defaultActions = [NSMutableArray new];
NSMutableArray *minimalActions = [NSMutableArray new];
Expand Down
1 change: 1 addition & 0 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ - (void)append:(id)args
[newData appendData:otherData];

[self setData:newData];
RELEASE_TO_NIL(newData);
}
}

Expand Down
16 changes: 14 additions & 2 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,30 @@ - (NSNumber *)append:(id)args
sourceOffset = (hasSourceOffset) ? sourceOffset : 0;
sourceLength = (hasSourceLength) ? sourceLength : [[source data] length];

if ([source data] == nil) {
[self throwException:@"TiBoundsException"
subreason:[NSString stringWithFormat:@"Source dats is nil"]
location:CODELOCATION];
return @(-1);
}

if (hasSourceOffset && !hasSourceLength) {
[self throwException:@"TiArgsException"
subreason:@"Ti.Buffer.append(buf,offset,length) requires three arguments"
location:CODELOCATION];
return @(-1);
}

if (sourceOffset + sourceLength > [[source data] length]) {
[self throwException:@"TiBoundsException"
subreason:[NSString stringWithFormat:@"Source offset %lu plus sourceLength %lu extends past source bounds (length %lu)", (unsigned long)sourceOffset, (unsigned long)sourceLength, (unsigned long)[[source data] length]]
location:CODELOCATION];
return @(-1);
}

NSUInteger length = MIN(sourceLength, [[source data] length] - sourceOffset);
const void *bytes = [[source data] bytes];

if (data == nil) {
data = [[NSMutableData alloc] initWithBytes:bytes + sourceOffset length:length];
} else {
Expand Down Expand Up @@ -137,8 +147,10 @@ - (NSNumber *)insert:(id)args
[data replaceBytesInRange:NSMakeRange(offset + length, [data length] - (offset + length)) withBytes:(currentBytes + offset)];

// 3.
const void *newBytes = [[source data] bytes];
[data replaceBytesInRange:NSMakeRange(offset, length) withBytes:(newBytes + sourceOffset)];
if ([source data] != nil) {
const void *newBytes = [[source data] bytes];
[data replaceBytesInRange:NSMakeRange(offset, length) withBytes:(newBytes + sourceOffset)];
}

return NUMUINTEGER(length);
}
Expand Down

0 comments on commit a56529c

Please sign in to comment.