Skip to content

Commit 3b7b736

Browse files
committed
Coverity PR: Fix some minor issues or add improvements
* MongoDB: goto "out_err" in the new if-block, to free the resources * mid-registrar: on mid_reg_save() quick-exit, check .flags before reply * EVI: fix "infinite loop" bug in evi_remove_expired_subs() * various whitespace fixes
1 parent b7fdd94 commit 3b7b736

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

evi/event_interface.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void evi_remove_expired_subs(event_id_t id) {
137137
while (subs) {
138138
if (!subs->reply_sock) {
139139
LM_ERR("unknown destination\n");
140-
continue;
140+
goto next_sub;
141141
}
142142
/* check expire */
143143
if (!(subs->reply_sock->flags & EVI_PENDING) &&
@@ -163,6 +163,7 @@ void evi_remove_expired_subs(event_id_t id) {
163163
}
164164
continue;
165165
}
166+
next_sub:
166167
prev = subs;
167168
subs = subs->next;
168169
}
@@ -771,7 +772,7 @@ mi_response_t *w_mi_subscribers_list_1(const mi_params_t *params,
771772
/* get the event id & before printing the subs list check for any expired subscribers and remove them*/
772773
evid = evi_get_id(&event_s);
773774
if (evid == -1)
774-
return init_mi_error(404, MI_SSTR("Can't get the id"));
775+
return init_mi_error(404, MI_SSTR("Can't get the id"));
775776

776777
evi_remove_expired_subs(evid);
777778

modules/auth_aka/auth_aka.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static int aka_challenge(struct sip_msg *_msg, struct aka_av_mgm *mgm, str *_rea
737737

738738
realm = (_realm?*_realm:str_init(""));
739739
if (count > 1) {
740-
avs = pkg_malloc(count * sizeof(struct aka_av *));
740+
avs = pkg_malloc(count * sizeof *avs);
741741
if (!avs) {
742742
LM_ERR("could not allocate %d AVs\n", count);
743743
return -1;

modules/auth_jwt/auth_jwt_certops.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ int extract_pub_key_from_cert(struct sip_msg* _msg, str* cert,
4545
/* TODO - if x5c just add beggining & end */
4646

4747
if (cert == NULL) {
48-
LM_ERR("Failed to parse certificate\n");
49-
goto err_free;
50-
}
48+
LM_ERR("Failed to parse certificate\n");
49+
return -1;
50+
}
5151

5252
bio = BIO_new_mem_buf((void*)cert->s,cert->len);
5353
if (!bio) {

modules/cachedb_mongodb/cachedb_mongodb_dbase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ int mongo_raw_find(cachedb_con *con, bson_t *raw_query, bson_iter_t *ns,
423423
#if MONGOC_CHECK_VERSION(1, 5, 0)
424424
if (!bson_append_document(opts, "projection", 10, &proj)) {
425425
LM_ERR("failed to append doc\n");
426-
return -1;
426+
goto out_err;
427427
}
428428
#else
429429
fields = &proj;

modules/cachedb_mongodb/cachedb_mongodb_json.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ int json_to_bson_append_element(bson_t *doc, const char *k, struct json_object *
7979

8080
if (!v) {
8181
if (!bson_append_null(doc, key, -1)) {
82-
LM_ERR("failed to append NULL doc\n");
83-
return -1;
84-
}
82+
LM_ERR("failed to append NULL doc\n");
83+
return -1;
84+
}
8585

8686
return 0;
8787
}

modules/mid_registrar/save.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,14 +2535,8 @@ int mid_reg_save(struct sip_msg *msg, udomain_t *d, struct save_flags *flags,
25352535
struct hdr_field *path;
25362536
int rc = -1, st, unlock_udomain = 0;
25372537

2538-
memset(&sctx, 0, sizeof sctx);
2539-
if (msg->REQ_METHOD != METHOD_REGISTER) {
2540-
LM_ERR("rejecting non-REGISTER SIP request (%d)\n", msg->REQ_METHOD);
2541-
rerrno = R_NOT_IMPL;
2542-
goto out_error;
2543-
}
2544-
25452538
rerrno = R_FINE;
2539+
memset(&sctx, 0, sizeof sctx);
25462540
sctx.cmatch.mode = CT_MATCH_NONE;
25472541
sctx.max_contacts = max_contacts;
25482542

@@ -2556,6 +2550,12 @@ int mid_reg_save(struct sip_msg *msg, udomain_t *d, struct save_flags *flags,
25562550
sctx.cmatch = flags->cmatch;
25572551
}
25582552

2553+
if (msg->REQ_METHOD != METHOD_REGISTER) {
2554+
LM_ERR("rejecting non-REGISTER SIP request (%d)\n", msg->REQ_METHOD);
2555+
rerrno = R_NOT_IMPL;
2556+
goto out_error;
2557+
}
2558+
25592559
if (parse_reg_headers(msg) != 0) {
25602560
LM_ERR("failed to parse req headers\n");
25612561
goto out_error;

modules/nat_traversal/nat_traversal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,9 +1932,9 @@ reply_filter(struct sip_msg *reply)
19321932
str call_id;
19331933

19341934
if (parse_headers(reply, HDR_VIA2_F, 0) < 0) {
1935-
LM_ERR("failed to parse message\n");
1936-
return -1;
1937-
}
1935+
LM_ERR("failed to parse message\n");
1936+
return -1;
1937+
}
19381938

19391939
if (reply->via2)
19401940
return 1;

0 commit comments

Comments
 (0)