From d259f4ef9e22cccaf998e86c8a1e98a3f43defd7 Mon Sep 17 00:00:00 2001 From: Maximilian Fridrich Date: Wed, 13 Jul 2022 12:23:12 +0200 Subject: [PATCH] sipsess: fix coverity warnings add sanity checks to invite_resp_handler and remove dead code part that is covered by sipsess_reply_xx functions. fixes #432 --- src/sipsess/accept.c | 22 ---------------------- src/sipsess/connect.c | 7 +++++-- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/sipsess/accept.c b/src/sipsess/accept.c index 9fb7cdddf..ab50daeff 100644 --- a/src/sipsess/accept.c +++ b/src/sipsess/accept.c @@ -109,28 +109,6 @@ int sipsess_accept(struct sipsess **sessp, struct sipsess_sock *sock, err = sipsess_reply_2xx(sess, msg, scode, reason, desc, fmt, &ap); } - else { - struct sip_contact contact; - - sip_contact_set(&contact, sess->cuser, &msg->dst, msg->tp); - - err = sip_treplyf(&sess->st, NULL, sess->sip, - msg, true, scode, reason, - "%H" - "%v" - "%s%s%s" - "Content-Length: %zu\r\n" - "\r\n" - "%b", - sip_contact_print, &contact, - fmt, &ap, - desc ? "Content-Type: " : "", - desc ? sess->ctype : "", - desc ? "\r\n" : "", - desc ? mbuf_get_left(desc) : (size_t)0, - desc ? mbuf_buf(desc) : NULL, - desc ? mbuf_get_left(desc) : (size_t)0); - } va_end(ap); diff --git a/src/sipsess/connect.c b/src/sipsess/connect.c index 15fb6ae4d..8810afc87 100644 --- a/src/sipsess/connect.c +++ b/src/sipsess/connect.c @@ -79,7 +79,10 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg) struct sipsess *sess = arg; struct mbuf *desc = NULL; - if (err || sip_request_loops(&sess->ls, msg->scode)) + if (!sess) + return; + + if (!msg || err || sip_request_loops(&sess->ls, msg->scode)) goto out; if (msg->scode < 200) { @@ -88,7 +91,7 @@ static void invite_resp_handler(int err, const struct sip_msg *msg, void *arg) if (sip_msg_hdr_has_value(msg, SIP_HDR_REQUIRE, "100rel") && sess->rel100_supported) { - if (msg && mbuf_get_left(msg->mb)) { + if (mbuf_get_left(msg->mb)) { if (sess->sent_offer) { sess->awaiting_answer = false; err = sess->answerh(msg, sess->arg);