From caf30a4b77b49c02f2d824969e7398b89627e811 Mon Sep 17 00:00:00 2001 From: Bart De Schuymer Date: Thu, 23 Jun 2011 18:24:38 +0000 Subject: fix possible issues found by Coverity static analysis (thanks to Jiri Popelka) --- communication.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'communication.c') diff --git a/communication.c b/communication.c index 4b89a65..3311358 100644 --- a/communication.c +++ b/communication.c @@ -66,7 +66,9 @@ static struct ebt_replace *translate_user2kernel(struct ebt_u_replace *u_repl) new->nentries = u_repl->nentries; new->num_counters = u_repl->num_counters; new->counters = sparc_cast u_repl->counters; - chain_offsets = (unsigned int *)malloc(u_repl->num_chains * sizeof(unsigned int)); + chain_offsets = (unsigned int *)calloc(u_repl->num_chains, sizeof(unsigned int)); + if (!chain_offsets) + ebt_print_memory(); /* Determine size */ for (i = 0; i < u_repl->num_chains; i++) { if (!(entries = u_repl->chains[i])) @@ -313,6 +315,8 @@ void ebt_deliver_counters(struct ebt_u_replace *u_repl) if (chainnr == u_repl->num_chains) break; } + if (next == NULL) + ebt_print_bug("next == NULL"); if (cc->type == CNT_NORM) { /* 'Normal' rule, meaning we didn't do anything to it * So, we just copy */ @@ -640,9 +644,9 @@ static int retrieve_from_file(char *filename, struct ebt_replace *repl, != repl->entries_size || fseek(file, sizeof(struct ebt_replace) + repl->entries_size, SEEK_SET) - || fread((char *)repl->counters, sizeof(char), + || (repl->counters && fread((char *)repl->counters, sizeof(char), repl->nentries * sizeof(struct ebt_counter), file) - != repl->nentries * sizeof(struct ebt_counter)) { + != repl->nentries * sizeof(struct ebt_counter))) { ebt_print_error("File %s is corrupt", filename); free(entries); repl->entries = NULL; -- cgit v1.2.3