mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-12-29 17:36:26 -05:00
fw: Go to state fail on bad command lengths
This commit is contained in:
parent
ebf8a11ed0
commit
78eb472ac9
@ -164,10 +164,8 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
|
|
||||||
htif_puts("cmd: name-version\n");
|
htif_puts("cmd: name-version\n");
|
||||||
if (hdr->len != 1) {
|
if (hdr->len != 1) {
|
||||||
// Bad length - give them an empty
|
// Bad length
|
||||||
// response
|
return FW_STATE_FAIL;
|
||||||
fwreply(*hdr, FW_RSP_NAME_VERSION, rsp);
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy_s(rsp, CMDLEN_MAXBYTES, &namever.name0, 4);
|
memcpy_s(rsp, CMDLEN_MAXBYTES, &namever.name0, 4);
|
||||||
@ -184,14 +182,11 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
|
|
||||||
htif_puts("cmd: get-udi\n");
|
htif_puts("cmd: get-udi\n");
|
||||||
if (hdr->len != 1) {
|
if (hdr->len != 1) {
|
||||||
// Bad cmd length
|
// Bad length
|
||||||
rsp[0] = STATUS_BAD;
|
return FW_STATE_FAIL;
|
||||||
fwreply(*hdr, FW_RSP_GET_UDI, rsp);
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp[0] = STATUS_OK;
|
rsp[0] = STATUS_OK;
|
||||||
|
|
||||||
wordcpy_s(udi_words, 2, (void *)udi, 2);
|
wordcpy_s(udi_words, 2, (void *)udi, 2);
|
||||||
memcpy_s(&rsp[1], CMDLEN_MAXBYTES - 1, udi_words, 2 * 4);
|
memcpy_s(&rsp[1], CMDLEN_MAXBYTES - 1, udi_words, 2 * 4);
|
||||||
fwreply(*hdr, FW_RSP_GET_UDI, rsp);
|
fwreply(*hdr, FW_RSP_GET_UDI, rsp);
|
||||||
@ -205,9 +200,7 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
htif_puts("cmd: load-app(size, uss)\n");
|
htif_puts("cmd: load-app(size, uss)\n");
|
||||||
if (hdr->len != 512) {
|
if (hdr->len != 512) {
|
||||||
// Bad length
|
// Bad length
|
||||||
rsp[0] = STATUS_BAD;
|
return FW_STATE_FAIL;
|
||||||
fwreply(*hdr, FW_RSP_LOAD_APP, rsp);
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd[1..4] contains the size.
|
// cmd[1..4] contains the size.
|
||||||
@ -221,6 +214,7 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
if (local_app_size == 0 || local_app_size > TK1_APP_MAX_SIZE) {
|
if (local_app_size == 0 || local_app_size > TK1_APP_MAX_SIZE) {
|
||||||
rsp[0] = STATUS_BAD;
|
rsp[0] = STATUS_BAD;
|
||||||
fwreply(*hdr, FW_RSP_LOAD_APP, rsp);
|
fwreply(*hdr, FW_RSP_LOAD_APP, rsp);
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,10 +259,8 @@ static int loading_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
case FW_CMD_LOAD_APP_DATA:
|
case FW_CMD_LOAD_APP_DATA:
|
||||||
htif_puts("cmd: load-app-data\n");
|
htif_puts("cmd: load-app-data\n");
|
||||||
if (hdr->len != 512) {
|
if (hdr->len != 512) {
|
||||||
// Bad cmd length
|
// Bad length
|
||||||
rsp[0] = STATUS_BAD;
|
return FW_STATE_FAIL;
|
||||||
fwreply(*hdr, FW_RSP_LOAD_APP_DATA, rsp);
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->left > (512 - 1)) {
|
if (ctx->left > (512 - 1)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user