Be consistent and check for errors first

This commit is contained in:
Daniel Lublin 2022-09-21 10:56:15 +02:00
parent c0334a77da
commit df67966d8f
No known key found for this signature in database
GPG Key ID: 75BD0FEB8D3E7830

View File

@ -205,14 +205,14 @@ int main()
case FW_CMD_RUN_APP: case FW_CMD_RUN_APP:
puts("request: run-app\n"); puts("request: run-app\n");
if (hdr.len != 1) { if (hdr.len != 1 || *app_size == 0 || *app_addr == 0) {
// Bad length // Bad cmd length, or app_size and app_addr are
// not both set
rsp[0] = STATUS_BAD; rsp[0] = STATUS_BAD;
fwreply(hdr, FW_RSP_RUN_APP, rsp); fwreply(hdr, FW_RSP_RUN_APP, rsp);
break; break;
} }
if (*app_size > 0 && *app_addr != 0) {
rsp[0] = STATUS_OK; rsp[0] = STATUS_OK;
fwreply(hdr, FW_RSP_RUN_APP, rsp); fwreply(hdr, FW_RSP_RUN_APP, rsp);
@ -238,11 +238,7 @@ int main()
"jalr x0,0(a0);" "jalr x0,0(a0);"
::: "memory"); ::: "memory");
// clang-format on // clang-format on
} break; // This is never reached!
rsp[0] = STATUS_BAD;
fwreply(hdr, FW_RSP_RUN_APP, rsp);
break;
case FW_CMD_GET_APP_DIGEST: case FW_CMD_GET_APP_DIGEST:
puts("request: get-app-digest\n"); puts("request: get-app-digest\n");