Skip to content

Commit

Permalink
fixing coverity found defects - null dereference
Browse files Browse the repository at this point in the history
(cherry picked from commit 906bb91)

Conflicts:
	cachedb/cachedb_id.c

(cherry picked from commit 37a7466)
  • Loading branch information
ph4r05 authored and liviuchircu committed Jan 18, 2016
1 parent 49c1d65 commit 8c9b818
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 25 deletions.
12 changes: 6 additions & 6 deletions cachedb/cachedb_id.c
Expand Up @@ -269,12 +269,12 @@ static int parse_cachedb_url(struct cachedb_id* id, const str* url)
return 0;

err:
if (id->initial_url) pkg_free(id->initial_url);
if (id->scheme) pkg_free(id->scheme);
if (id->username) pkg_free(id->username);
if (id->password) pkg_free(id->password);
if (id->host) pkg_free(id->host);
if (id->database) pkg_free(id->database);
if (id && id->initial_url) pkg_free(id->initial_url);
if (id && id->scheme) pkg_free(id->scheme);
if (id && id->username) pkg_free(id->username);
if (id && id->password) pkg_free(id->password);
if (id && id->host) pkg_free(id->host);
if (id && id->database) pkg_free(id->database);
if (prev_token) pkg_free(prev_token);
return -1;
}
Expand Down
9 changes: 6 additions & 3 deletions db/db_query.c
Expand Up @@ -118,7 +118,8 @@ int db_do_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
err_exit:
if (_r)
*_r = NULL;
CON_OR_RESET(_h);
if (_h)
CON_OR_RESET(_h);
return -1;
}

Expand Down Expand Up @@ -341,7 +342,8 @@ int db_do_delete(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
error:
LM_ERR("error while preparing delete operation\n");
err_exit:
CON_OR_RESET(_h);
if (_h)
CON_OR_RESET(_h);
return -1;
}

Expand Down Expand Up @@ -392,7 +394,8 @@ int db_do_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
error:
LM_ERR("error while preparing update operation\n");
err_exit:
CON_OR_RESET(_h);
if(_h)
CON_OR_RESET(_h);
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions modules/cachedb_local/cachedb_local.c
Expand Up @@ -204,13 +204,13 @@ lcache_con* lcache_new_connection(struct cachedb_id* id)
{
lcache_con *con;

if (id->flags != CACHEDB_ID_NO_URL) {
LM_ERR("bogus url for local cachedb\n");
if (id == NULL) {
LM_ERR("null db_id\n");
return 0;
}

if (id == NULL) {
LM_ERR("null db_id\n");
if (id->flags != CACHEDB_ID_NO_URL) {
LM_ERR("bogus url for local cachedb\n");
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions modules/cachedb_sql/cachedb_sql.c
Expand Up @@ -272,7 +272,7 @@ static int dbcache_get(cachedb_con *con, str* attr, str* res)
return -1;
}

if (RES_ROW_N(db_res) <= 0 || RES_ROWS(db_res)[0].values[0].nul != 0) {
if (db_res == NULL || RES_ROW_N(db_res) <= 0 || RES_ROWS(db_res)[0].values[0].nul != 0) {
LM_DBG("no value found for keyI\n");
if (db_res != NULL && CACHEDBSQL_FUNC(con).free_result(CACHEDBSQL_CON(con),db_res) < 0)
LM_DBG("failed to free result of query\n");
Expand Down Expand Up @@ -439,7 +439,7 @@ static int dbcache_fetch_counter(cachedb_con *con,str *attr,int *ret_val)
return -1;
}

if (RES_ROW_N(db_res) <= 0 || RES_ROWS(db_res)[0].values[0].nul != 0) {
if (db_res == NULL || RES_ROW_N(db_res) <= 0 || RES_ROWS(db_res)[0].values[0].nul != 0) {
LM_DBG("no value found for keyI\n");
if (db_res != NULL && CACHEDBSQL_FUNC(con).free_result(CACHEDBSQL_CON(con), db_res) < 0)
LM_DBG("failed to free result of query\n");
Expand Down
5 changes: 3 additions & 2 deletions modules/db_postgres/dbase.c
Expand Up @@ -269,9 +269,10 @@ int db_postgres_fetch_result(const db_con_t* _con, db_res_t** _res, const int nr
LM_ERR("%p - invalid query, execution aborted\n", _con);
LM_ERR("%p - PQresultStatus(%s)\n",_con,PQresStatus(pqresult));
LM_ERR("%p: %s\n",_con,PQresultErrorMessage(CON_RESULT(_con)));
if (*_res)
if (*_res) {
db_free_result(*_res);
*_res = 0;
*_res = 0;
}
return -3;

case PGRES_EMPTY_QUERY:
Expand Down
4 changes: 2 additions & 2 deletions modules/dialog/dlg_profile.c
Expand Up @@ -1147,8 +1147,8 @@ struct mi_root * mi_get_profile_values(struct mi_root *cmd_tree, void *param )

return rpl_tree;
error:

free_mi_tree(rpl_tree);
if (rpl_tree)
free_mi_tree(rpl_tree);
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/httpd/httpd_proc.c
Expand Up @@ -216,7 +216,7 @@ static int post_iterator (void *cls,
pr = (struct post_request*)cls;
if (pr==NULL) {
LM_CRIT("corrupted data: null cls\n");
pr->status = -1; return MHD_NO;
return MHD_NO;
}

if (off!=0) {
Expand Down
4 changes: 2 additions & 2 deletions modules/load_balancer/lb_db.c
Expand Up @@ -114,7 +114,7 @@ int init_lb_db(const str *db_url, char *table)
int lb_db_load_data( struct lb_data *data)
{
db_key_t columns[5];
db_res_t* res;
db_res_t* res = NULL;
db_row_t* row;
int i, n;
char *resource, *uri;
Expand Down Expand Up @@ -149,7 +149,7 @@ int lb_db_load_data( struct lb_data *data)
}
}

if (RES_ROW_N(res) == 0) {
if (res == NULL || RES_ROW_N(res) == 0) {
LM_WARN("table \"%.*s\" empty\n", lb_table_name.len,lb_table_name.s );
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions modules/permissions/hash.c
Expand Up @@ -228,6 +228,10 @@ int find_group_in_hash_table(struct address_list** table,
struct address_list *node;
str str_ip;

if (ip == NULL){
return -1;
}

str_ip.len = ip->len;
str_ip.s = (char*) ip->u.addr;

Expand Down
2 changes: 1 addition & 1 deletion modules/presence/notify.c
Expand Up @@ -2123,7 +2123,7 @@ void p_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
((c_back_param*)(*ps->param))->to_tag.s== NULL)
{
LM_DBG("message id not received\n");
if(*ps->param !=NULL )
if(ps->param!=NULL && *ps->param !=NULL )
free_cbparam((c_back_param*)(*ps->param));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/registrar/lookup.c
Expand Up @@ -260,7 +260,7 @@ int lookup(struct sip_msg* _m, char* _t, char* _f, char* _s)
it = ptr->next;
while ( it ) {
if (VALID_CONTACT(it,act_time)) {
if (it->instance.len-2 == sip_instance.len &&
if (it->instance.len-2 == sip_instance.len && sip_instance.s &&
memcmp(it->instance.s+1,sip_instance.s,sip_instance.len) == 0)
if (it->last_modified > ptr->last_modified) {
/* same instance id, but newer modified -> expired GRUU, no match at all */
Expand Down
2 changes: 1 addition & 1 deletion parser/sdp/sdp.c
Expand Up @@ -823,7 +823,7 @@ void print_sdp_stream(sdp_stream_cell_t *stream, int log_level)

void print_sdp_session(sdp_session_cell_t *session, int log_level)
{
sdp_stream_cell_t *stream = session->streams;
sdp_stream_cell_t *stream = session==NULL ? NULL : session->streams;

if (session==NULL) {
LM_ERR("NULL session\n");
Expand Down

0 comments on commit 8c9b818

Please sign in to comment.