[Asterisk-code-review] chan_unistim: Fix clang warning: variable sized type not at end of a ... (...asterisk[13])

George Joseph asteriskteam at digium.com
Tue Sep 10 08:41:30 CDT 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/12807 )

Change subject: chan_unistim: Fix clang warning: variable sized type not at end of a struct
......................................................................

chan_unistim: Fix clang warning: variable sized type not at end of a struct

On reading information about initial client packet unistim use dirty
implementation of destination ip address retrieval. This fix uses
CMSG_*(..) to get ip address and make clang compile without warning.

ASTERISK-25592 #close
Reported-by: Alexander Traud

Change-Id: Ic1fd34c2c2bcc951da65bf62e3f7a8adff8351b1
---
M channels/chan_unistim.c
1 file changed, 31 insertions(+), 18 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index b846585..63721d9 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -1004,27 +1004,36 @@
 {
 #ifdef HAVE_PKTINFO
 	int err;
-	struct msghdr msg;
-	struct {
-		struct cmsghdr cm;
-		int len;
-		struct in_addr address;
-	} ip_msg;
-
-	/* Zero out the structures before we use them */
-	/* This sets several key values to NULL */
-	memset(&msg, 0, sizeof(msg));
-	memset(&ip_msg, 0, sizeof(ip_msg));
-
-	/* Initialize the message structure */
-	msg.msg_control = &ip_msg;
-	msg.msg_controllen = sizeof(ip_msg);
+	char cmbuf[0x100];
+	struct cmsghdr *cmsg;
+	struct sockaddr_in peeraddr;
+	struct in_addr addr;
+	struct msghdr mh = {
+		.msg_name = &peeraddr,
+		.msg_namelen = sizeof(peeraddr),
+		.msg_control = cmbuf,
+		.msg_controllen = sizeof(cmbuf),
+	};
+	memset(&addr, 0, sizeof(addr));
 	/* Get info about the incoming packet */
-	err = recvmsg(fd, &msg, MSG_PEEK);
+	err = recvmsg(fd, &mh, MSG_PEEK);
 	if (err == -1) {
 		ast_log(LOG_WARNING, "recvmsg returned an error: %s\n", strerror(errno));
+		return err;
 	}
-	memcpy(&toAddr->sin_addr, &ip_msg.address, sizeof(struct in_addr));
+	for(cmsg = CMSG_FIRSTHDR(&mh);
+		cmsg != NULL;
+		cmsg = CMSG_NXTHDR(&mh, cmsg))
+	{
+		 if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO) {
+			struct in_pktinfo *pkt = (struct in_pktinfo*)CMSG_DATA(cmsg);
+			addr = pkt->ipi_addr;
+			if (unistimdebug) {
+				ast_verb(0, "message received on address %s\n", ast_inet_ntoa(addr));
+			}
+		}
+	}
+	memcpy(&toAddr->sin_addr, &addr, sizeof(struct in_addr));
 	return err;
 #else
 	memcpy(toAddr, &public_ip, sizeof(*toAddr));
@@ -1032,6 +1041,7 @@
 #endif
 }
 
+
 /* Allocate memory & initialize structures for a new phone */
 /* addr_from : ip address of the phone */
 static struct unistimsession *create_client(const struct sockaddr_in *addr_from)
@@ -1043,7 +1053,10 @@
 		return NULL;
 
 	memcpy(&s->sin, addr_from, sizeof(struct sockaddr_in));
-	get_to_address(unistimsock, &s->sout);
+	if (get_to_address(unistimsock, &s->sout) < 0) {
+		ast_free(s);
+		return NULL;
+	}
 	s->sout.sin_family = AF_INET;
 	if (unistimdebug) {
 		ast_verb(0, "Creating a new entry for the phone from %s received via server ip %s\n",

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12807
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ic1fd34c2c2bcc951da65bf62e3f7a8adff8351b1
Gerrit-Change-Number: 12807
Gerrit-PatchSet: 2
Gerrit-Owner: Igor Goncharovsky <igor.goncharovsky at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Igor Goncharovsky <igor.goncharovsky at gmail.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190910/80d21d83/attachment.html>


More information about the asterisk-code-review mailing list