[PATCH] openbsc: Fix coverity issues

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Fri Jan 17 08:22:57 UTC 2014


This patch (hopefully) fixes the new defects reported by coverity.

Addresses:
** CID 1156986:  Negative array index read  (NEGATIVE_RETURNS)
/tests/gsm0408/gsm0408_test.c: 419 in test_si_range_helpers()
/tests/gsm0408/gsm0408_test.c: 423 in test_si_range_helpers()
/tests/gsm0408/gsm0408_test.c: 427 in test_si_range_helpers()

** CID 1156987:  Unchecked return value from library
(CHECKED_RETURN)
/src/libmgcp/mgcp_protocol.c: 1150 in mgcp_keepalive_timer_cb()

** CID 1156988:  Unchecked return value from library
(CHECKED_RETURN)
/src/libmgcp/mgcp_protocol.c: 983 in handle_modify_con()

Sponsored-by: On-Waves ehf
---
 openbsc/src/libmgcp/mgcp_network.c   |   19 ++++++++++++++++---
 openbsc/tests/gsm0408/gsm0408_test.c |    6 +++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index 0cc2041..b55ac04 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -134,11 +134,24 @@ int mgcp_send_dummy(struct mgcp_endpoint *endp)
 	rc = mgcp_udp_send(endp->net_end.rtp.fd, &endp->net_end.addr,
 			   endp->net_end.rtp_port, buf, 1);
 
-	if (rc == -1 || endp->tcfg->omit_rtcp)
+	if (rc == -1)
+		goto failed;
+
+	if (endp->tcfg->omit_rtcp)
+		return rc;
+
+	rc = mgcp_udp_send(endp->net_end.rtcp.fd, &endp->net_end.addr,
+			   endp->net_end.rtcp_port, buf, 1);
+
+	if (rc >= 0)
 		return rc;
 
-	return mgcp_udp_send(endp->net_end.rtcp.fd, &endp->net_end.addr,
-			     endp->net_end.rtcp_port, buf, 1);
+failed:
+	LOGP(DMGCP, LOGL_ERROR,
+	     "Failed to send dummy packet: %s on: 0x%x to %s\n",
+	     strerror(errno), ENDPOINT_NUMBER(endp), inet_ntoa(endp->net_end.addr));
+
+	return -1;
 }
 
 static int32_t compute_timestamp_aligment_error(struct mgcp_rtp_stream_state *sstate,
diff --git a/openbsc/tests/gsm0408/gsm0408_test.c b/openbsc/tests/gsm0408/gsm0408_test.c
index 894eb0f..38c1a6a 100644
--- a/openbsc/tests/gsm0408/gsm0408_test.c
+++ b/openbsc/tests/gsm0408/gsm0408_test.c
@@ -416,15 +416,15 @@ static void test_si_range_helpers()
 	memset(&ws[0], 0x23, sizeof(ws));
 
 	i = range_enc_find_index(1023, freqs1, ARRAY_SIZE(freqs1));
-	printf("Element is: %d => freqs[i] = %d\n", i, freqs1[i]);
+	printf("Element is: %d => freqs[i] = %d\n", i, i >= 0 ? freqs1[i] : -1);
 	VERIFY(i, ==, 2);
 
 	i = range_enc_find_index(511, freqs2, ARRAY_SIZE(freqs2));
-	printf("Element is: %d => freqs[i] = %d\n", i, freqs2[i]);
+	printf("Element is: %d => freqs[i] = %d\n", i,  i >= 0 ? freqs2[i] : -1);
 	VERIFY(i, ==, 2);
 
 	i = range_enc_find_index(511, freqs3, ARRAY_SIZE(freqs3));
-	printf("Element is: %d => freqs[i] = %d\n", i, freqs3[i]);
+	printf("Element is: %d => freqs[i] = %d\n", i,  i >= 0 ? freqs3[i] : -1);
 	VERIFY(i, ==, 0);
 
 	i = range_enc_arfcns(1023, freqs1, ARRAY_SIZE(freqs1), ws, 0);
-- 
1.7.9.5





More information about the OpenBSC mailing list