Skip to content

Commit

Permalink
tools/firewire: nosy-dump: check for allocation failure
Browse files Browse the repository at this point in the history
Behavior of null pointer dereference is undefined in the C language.
Portably implement the desired behavior.

Reported-by: Yang Yeping <[email protected]>
Signed-off-by: Stefan Richter <[email protected]>
  • Loading branch information
Stefan Richter committed Dec 2, 2012
1 parent 9489e9d commit 6fa79bc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/firewire/nosy-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6fa79bc

Please sign in to comment.