Change in osmo-mgw[master]: check_rtp_origin(): Avoid using memcmp for comparing integer types

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/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Oct 21 10:02:07 UTC 2018


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/11403


Change subject: check_rtp_origin(): Avoid using memcmp for comparing integer types
......................................................................

check_rtp_origin(): Avoid using memcmp for comparing integer types

in_addr consists only of s_addr, which is an integer type that
can be compared directly.  By avoiding memcmp() here we would have
been able to catch Coverity CID#188874 even without Coverity, and
make the code more compact...

Change-Id: Ic6105d39ae2fb4b301f87448b16763fe9f695621
---
M src/libosmo-mgcp/mgcp_network.c
1 file changed, 2 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/03/11403/1

diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index fe63f1e..de34cc6 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -872,9 +872,8 @@
 {
 	struct mgcp_endpoint *endp;
 	endp = conn->conn->endp;
-	struct sockaddr_in zero_addr = {};
 
-	if (memcmp(&zero_addr.sin_addr, &conn->end.addr, sizeof(zero_addr.sin_addr)) == 0) {
+	if (conn->end.addr.s_addr == 0) {
 		switch (conn->conn->mode) {
 		case MGCP_CONN_LOOPBACK:
 			/* HACK: for IuUP, we want to reply with an IuUP Initialization ACK upon the first RTP
@@ -904,8 +903,7 @@
 
 	/* Note: Check if the inbound RTP data comes from the same host to
 	 * which we send our outgoing RTP traffic. */
-	if (memcmp(&addr->sin_addr, &conn->end.addr, sizeof(addr->sin_addr))
-	    != 0) {
+	if (conn->end.addr.s_addr != addr->sin_addr.s_addr) {
 		LOGP(DRTP, LOGL_ERROR,
 		     "endpoint:0x%x data from wrong address: %s, ",
 		     ENDPOINT_NUMBER(endp), inet_ntoa(addr->sin_addr));

-- 
To view, visit https://gerrit.osmocom.org/11403
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic6105d39ae2fb4b301f87448b16763fe9f695621
Gerrit-Change-Number: 11403
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181021/45deb6c0/attachment.htm>


More information about the gerrit-log mailing list