Skip to content

Commit

Permalink
Merge pull request #260 from NordicSemiconductor/nil-parameters
Browse files Browse the repository at this point in the history
Crash Fix for nil McuMgr Parameters Response
  • Loading branch information
dinesharjani authored Sep 13, 2024
2 parents c04b677 + 8f834f0 commit 76f7dbe
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Source/Managers/DFU/FirmwareUpgradeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,19 @@ public class FirmwareUpgradeManager: FirmwareUpgradeController, ConnectionObserv
return
}

self.log(msg: "Mcu Manager parameters received (\(response.bufferCount) x \(response.bufferSize))", atLevel: .application)
if response.bufferSize > UInt16.max {
response.bufferSize = UInt64(UInt16.max)
guard let bufferCount = response.bufferCount, var bufferSize = response.bufferSize else {
self.log(msg: "Mcu Manager parameters did not return an error, but neither did it provide valide bufferCount nor bufferSize values.", atLevel: .warning)
self.bootloaderInfo() // Continue to Bootloader Info.
return
}

self.log(msg: "Mcu Manager parameters received (\(bufferCount) x \(bufferSize))", atLevel: .application)
if bufferSize > UInt16.max {
bufferSize = UInt64(UInt16.max)
self.log(msg: "Parameters SAR Buffer Size is larger than maximum of \(UInt16.max) bytes. Reducing Buffer Size to maximum value.", atLevel: .warning)
}
self.log(msg: "Setting SAR Buffer Size to \(response.bufferSize) bytes.", atLevel: .verbose)
self.configuration.reassemblyBufferSize = response.bufferSize
self.log(msg: "Setting SAR Buffer Size to \(bufferSize) bytes.", atLevel: .verbose)
self.configuration.reassemblyBufferSize = bufferSize
self.bootloaderInfo() // Continue to Bootloader Mode.
}

Expand Down

0 comments on commit 76f7dbe

Please sign in to comment.