Skip to content

Commit 83cfd06

Browse files
authored
Merge pull request #293 from padelsbach/padelsbach/finding-146
Address chunk size issue in wh_Client_SheSecureBoot
2 parents 3d6f973 + 8a1da7a commit 83cfd06

File tree

2 files changed

+230
-59
lines changed

2 files changed

+230
-59
lines changed

src/wh_client_she.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
156156
while (ret == 0 && bootloaderSent < bootloaderLen) {
157157
uint8_t* in;
158158
uint32_t justSent;
159+
uint32_t remaining;
160+
static const uint32_t maxChunk =
161+
WOLFHSM_CFG_COMM_DATA_LEN - sizeof(*updateReq);
159162

160163
if (initResp->rc != WH_SHE_ERC_NO_ERROR) {
161164
return initResp->rc;
@@ -168,8 +171,8 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader,
168171
in = (uint8_t*)(updateReq + 1);
169172

170173
/* send what's left in the size available */
171-
updateReq->sz = ((bootloaderLen - bootloaderSent) %
172-
(WOLFHSM_CFG_COMM_DATA_LEN - sizeof(*updateReq)));
174+
remaining = bootloaderLen - bootloaderSent;
175+
updateReq->sz = (remaining > maxChunk) ? maxChunk : remaining;
173176

174177
justSent = updateReq->sz;
175178
memcpy(in, bootloader + bootloaderSent, updateReq->sz);

0 commit comments

Comments
 (0)