aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Anselmi <danselmi@gmx.ch>2023-04-11 10:18:33 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2023-04-30 14:51:11 +0000
commitbabec0fafa7141515c606790947f66bde46396b8 (patch)
tree5f1bc680a3c7ba8a1a86e4c7409be82f5ec9df62
parent3dfc0339fc85d467bed5cd435bb953bc7d3b9343 (diff)
downloadriscv-openocd-babec0fafa7141515c606790947f66bde46396b8.zip
riscv-openocd-babec0fafa7141515c606790947f66bde46396b8.tar.gz
riscv-openocd-babec0fafa7141515c606790947f66bde46396b8.tar.bz2
server/ipdbg: add error checks after allocating memory
Change-Id: Icf18a855eb66d2b09789a9ee27f5fbc4cd9afc89 Signed-off-by: Daniel Anselmi <danselmi@gmx.ch> Reviewed-on: https://review.openocd.org/c/openocd/+/7605 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-rw-r--r--src/server/ipdbg.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/server/ipdbg.c b/src/server/ipdbg.c
index 755d051..69d0f57 100644
--- a/src/server/ipdbg.c
+++ b/src/server/ipdbg.c
@@ -315,6 +315,10 @@ static int ipdbg_shift_instr(struct ipdbg_hub *hub, uint32_t instr)
}
uint8_t *ir_out_val = calloc(DIV_ROUND_UP(tap->ir_length, 8), 1);
+ if (!ir_out_val) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
buf_set_u32(ir_out_val, 0, tap->ir_length, instr);
struct scan_field fields;
@@ -344,6 +348,10 @@ static int ipdbg_shift_vir(struct ipdbg_hub *hub)
return ERROR_FAIL;
uint8_t *dr_out_val = calloc(DIV_ROUND_UP(hub->virtual_ir->length, 8), 1);
+ if (!dr_out_val) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
buf_set_u32(dr_out_val, 0, hub->virtual_ir->length, hub->virtual_ir->value);
struct scan_field fields;
@@ -366,8 +374,21 @@ static int ipdbg_shift_data(struct ipdbg_hub *hub, uint32_t dn_data, uint32_t *u
return ERROR_FAIL;
uint8_t *dr_out_val = calloc(DIV_ROUND_UP(hub->data_register_length, 8), 1);
+ if (!dr_out_val) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
buf_set_u32(dr_out_val, 0, hub->data_register_length, dn_data);
- uint8_t *dr_in_val = up_data ? calloc(DIV_ROUND_UP(hub->data_register_length, 8), 1) : NULL;
+
+ uint8_t *dr_in_val = NULL;
+ if (up_data) {
+ dr_in_val = calloc(DIV_ROUND_UP(hub->data_register_length, 8), 1);
+ if (!dr_in_val) {
+ LOG_ERROR("Out of memory");
+ free(dr_out_val);
+ return ERROR_FAIL;
+ }
+ }
struct scan_field fields;
ipdbg_init_scan_field(&fields, dr_in_val, hub->data_register_length, dr_out_val);