summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kinney <michaelakinney@comcast.net>2021-02-23 11:13:45 -0500
committerMichael Kinney <michaelakinney@comcast.net>2021-02-23 11:13:45 -0500
commit918e39c7cd9ea2535bd83f20501a040ccb4dede7 (patch)
treef077d001bf86dda23591c472af6bcb7dc3a88f47
parentd46ecdad8976590b0f2bf3f58b50c2853d9250c9 (diff)
downloadsdl_ios-918e39c7cd9ea2535bd83f20501a040ccb4dede7.tar.gz
ensure byteswritten is not negative to prevent range crash
-rw-r--r--SmartDeviceLink/private/SDLIAPDataSession.m16
1 files changed, 10 insertions, 6 deletions
diff --git a/SmartDeviceLink/private/SDLIAPDataSession.m b/SmartDeviceLink/private/SDLIAPDataSession.m
index c19a99a4d..4ddc71544 100644
--- a/SmartDeviceLink/private/SDLIAPDataSession.m
+++ b/SmartDeviceLink/private/SDLIAPDataSession.m
@@ -55,14 +55,18 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableData *remainder = [self.sendDataQueue frontBuffer];
if (remainder != nil) {
NSUInteger bytesRemaining = remainder.length;
- // SDLLogD(@"SDLIAPDataSession sending data for IAPSession %@.", self.iapSession);
[self.iapSession write:remainder length:bytesRemaining withCompletionHandler:^(NSInteger bytesWritten) {
- if (bytesWritten == bytesRemaining) {
- [self.sendDataQueue popBuffer];
+ if (bytesWritten >= 0) {
+ if (bytesWritten == bytesRemaining) {
+ [self.sendDataQueue popBuffer];
+ } else {
+ // Cleave the sent bytes from the data, the remainder will sit at the head of the queue
+ SDLLogD(@"SDLIAPDataSession writeDataToSessionStream bytes written %ld", (long)bytesWritten);
+ [remainder replaceBytesInRange:NSMakeRange(0, (NSUInteger)bytesWritten) withBytes:NULL length:0];
+ }
} else {
- // Cleave the sent bytes from the data, the remainder will sit at the head of the queue
- // SDLLogD(@"SDLIAPDataSession writeDataToSessionStream bytes written %ld", (long)bytesWritten);
- [remainder replaceBytesInRange:NSMakeRange(0, (NSUInteger)bytesWritten) withBytes:NULL length:0];
+ // The write operation failed but there is no further information about the error. This can occur when disconnecting from an external accessory.
+ SDLLogE(@"Output stream write operation failed");
}
}];
} else {