allocate CSR on heap instead of stack
@@ -36,15 +36,23 @@ oc_event_callback_retval_t generate_csr(void *data)
{
struct csr_callback_params *params = data;
size_t device = params->device;
- unsigned char csr[4096];
+ unsigned char csr = malloc(4096);
oc_set_separate_response_buffer(&csr_response);
+ if (!csr) {
+ oc_send_separate_response(&csr_response, OC_STATUS_INTERNAL_SERVER_ERROR);
+ free(params);
+ free(csr);
+ return OC_EVENT_DONE;
+ }
+
int ret = oc_certs_generate_csr(device, csr, OC_PDU_SIZE);
if (ret != 0) {
oc_send_separate_response(&csr_response, OC_STATUS_INTERNAL_SERVER_ERROR);
free(params);
+ free(csr);
return OC_EVENT_DONE;
}
@@ -58,6 +66,7 @@ oc_event_callback_retval_t generate_csr(void *data)
oc_rep_end_root_object();
oc_send_separate_response(&csr_response, OC_STATUS_OK);
+ free(params);
}
return OC_EVENT_DONE;
}
