]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
tools/firewire: nosy-dump: check for allocation failure
authorStefan Richter <stefanr@s5r6.in-berlin.de>
Mon, 22 Oct 2012 13:17:17 +0000 (15:17 +0200)
committerStefan Richter <stefanr@s5r6.in-berlin.de>
Sun, 2 Dec 2012 19:10:18 +0000 (20:10 +0100)
Behavior of null pointer dereference is undefined in the C language.
Portably implement the desired behavior.

Reported-by: Yang Yeping <yangyeping_666@hotmail.com>
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
tools/firewire/nosy-dump.c

index f93b776370b6f31fc52d68fe9b3dbf8085d34ed3..3179c711bd65e159ed5a043c42dfa43fa3333f41 100644 (file)
@@ -150,6 +150,8 @@ subaction_create(uint32_t *data, size_t length)
 
        /* we put the ack in the subaction struct for easy access. */
        sa = malloc(sizeof *sa - sizeof sa->packet + length);
+       if (!sa)
+               exit(EXIT_FAILURE);
        sa->ack = data[length / 4 - 1];
        sa->length = length;
        memcpy(&sa->packet, data, length);
@@ -180,6 +182,8 @@ link_transaction_lookup(int request_node, int response_node, int tlabel)
        }
 
        t = malloc(sizeof *t);
+       if (!t)
+               exit(EXIT_FAILURE);
        t->request_node = request_node;
        t->response_node = response_node;
        t->tlabel = tlabel;