server/ipdbg: add error checks after allocating memory 05/7605/2
authorDaniel Anselmi <danselmi@gmx.ch>
Tue, 11 Apr 2023 08:18:33 +0000 (10:18 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 30 Apr 2023 14:51:11 +0000 (14:51 +0000)
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>
src/server/ipdbg.c

index 755d0510edf5e21f36a17d7b74bdc547802d4b38..69d0f57553d775746fd4e2b06c8f77294ead0f04 100644 (file)
@@ -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);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)