diff options
author | Justin Beharry <justin.beharry@livio.io> | 2022-10-12 11:19:25 -0400 |
---|---|---|
committer | Justin Beharry <justin.beharry@livio.io> | 2022-10-12 11:19:25 -0400 |
commit | bb34d61e2f4cf2d277b9ceb094bd6b0e62786326 (patch) | |
tree | 10fe6dedc3501d741dc8e2607cc2385439b60af5 | |
parent | 7c031cb1a616cd361076368af18e6dd2bcdf6129 (diff) | |
download | sdl_ios-bb34d61e2f4cf2d277b9ceb094bd6b0e62786326.tar.gz |
Add check for cleaving if out of range
-Add error messaging
-Remove the corrupted buffer
-rw-r--r-- | SmartDeviceLink/private/SDLIAPDataSession.m | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/SmartDeviceLink/private/SDLIAPDataSession.m b/SmartDeviceLink/private/SDLIAPDataSession.m index 06d2e1f1d..be8b8cfbb 100644 --- a/SmartDeviceLink/private/SDLIAPDataSession.m +++ b/SmartDeviceLink/private/SDLIAPDataSession.m @@ -58,10 +58,14 @@ NS_ASSUME_NONNULL_BEGIN if (bytesWritten >= 0) { if (bytesWritten == bytesRemaining) { [self.sendDataQueue popBuffer]; - } else { + } else if (bytesRemaining > bytesWritten) { // Cleave the sent bytes from the data, the remainder will sit at the head of the queue SDLLogV(@"SDLIAPDataSession writeDataToSessionStream bytes written %ld", (long)bytesWritten); [remainder replaceBytesInRange:NSMakeRange(0, (NSUInteger)bytesWritten) withBytes:NULL length:0]; + } else { + // Error processing current data. Remove corrupted buffer + SDLLogE(@"Unable to remove sent bytes. Bytes remaining is less than bytes written %lu < %lu. Clearing buffer", bytesRemaining, bytesWritten); + [self.sendDataQueue popBuffer]; } } else { // The write operation failed but there is no further information about the error. This can occur when disconnecting from an external accessory. |