[Asterisk-code-review] coverity: Fix warnings in res smdi (asterisk[13])

Jenkins2 asteriskteam at digium.com
Fri Dec 15 10:50:17 CST 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7579 )

Change subject: coverity: Fix warnings in res_smdi
......................................................................

coverity: Fix warnings in res_smdi

ASTERISK-19657 #close
Reported by: Matt Jordan III, Esq.

Change-Id: I59a5e6ef3e7d9e848bec1f4b40cb73321bc7956a
---
M res/res_smdi.c
1 file changed, 36 insertions(+), 8 deletions(-)

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



diff --git a/res/res_smdi.c b/res/res_smdi.c
index 7b4c42b..1dc9cbe 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -588,9 +588,8 @@
 	struct ast_smdi_interface *iface = iface_p;
 	struct ast_smdi_md_message *md_msg;
 	struct ast_smdi_mwi_message *mwi_msg;
-	char c = '\0';
 	char *cp = NULL;
-	int i;
+	int i, c;
 	int start = 0;
 
 	/* read an smdi message */
@@ -618,7 +617,14 @@
 
 			/* read the message desk number */
 			for (i = 0; i < sizeof(md_msg->mesg_desk_num) - 1; i++) {
-				md_msg->mesg_desk_num[i] = fgetc(iface->file);
+				c = fgetc(iface->file);
+				if (c == EOF) {
+					ast_log(LOG_ERROR, "Unexpected EOF while reading MD message\n");
+					ao2_ref(md_msg, -1);
+					ao2_ref(iface, -1);
+					return NULL;
+				}
+				md_msg->mesg_desk_num[i] = (char) c;
 				ast_debug(1, "Read a '%c'\n", md_msg->mesg_desk_num[i]);
 			}
 
@@ -628,7 +634,14 @@
 
 			/* read the message desk terminal number */
 			for (i = 0; i < sizeof(md_msg->mesg_desk_term) - 1; i++) {
-				md_msg->mesg_desk_term[i] = fgetc(iface->file);
+				c = fgetc(iface->file);
+				if (c == EOF) {
+					ast_log(LOG_ERROR, "Unexpected EOF while reading SMDI message\n");
+					ao2_ref(md_msg, -1);
+					ao2_ref(iface, -1);
+					return NULL;
+				}
+				md_msg->mesg_desk_term[i] = (char) c;
 				ast_debug(1, "Read a '%c'\n", md_msg->mesg_desk_term[i]);
 			}
 
@@ -637,7 +650,14 @@
 			ast_debug(1, "The message desk terminal is '%s'\n", md_msg->mesg_desk_term);
 
 			/* read the message type */
-			md_msg->type = fgetc(iface->file);
+			c = fgetc(iface->file);
+			if (c == EOF) {
+				ast_log(LOG_ERROR, "Unexpected EOF while reading SMDI message\n");
+				ao2_ref(md_msg, -1);
+				ao2_ref(iface, -1);
+				return NULL;
+			}
+			md_msg->type = (char) c;
 
 			ast_debug(1, "Message type is '%c'\n", md_msg->type);
 
@@ -719,7 +739,7 @@
 
 			/* discard the 'I' (from 'MWI') */
 			fgetc(iface->file);
-			
+
 			/* read the forwarding station number (may be blank) */
 			cp = &mwi_msg->fwd_st[0];
 			for (i = 0; i < sizeof(mwi_msg->fwd_st) - 1; i++) {
@@ -742,8 +762,16 @@
 			ast_copy_string(mwi_msg->name, mwi_msg->fwd_st, sizeof(mwi_msg->name));
 
 			/* read the mwi failure cause */
-			for (i = 0; i < sizeof(mwi_msg->cause) - 1; i++)
-				mwi_msg->cause[i] = fgetc(iface->file);
+			for (i = 0; i < sizeof(mwi_msg->cause) - 1; i++) {
+				c = fgetc(iface->file);
+				if (c == EOF) {
+					ast_log(LOG_ERROR, "Unexpected EOF while reading MWI message\n");
+					ao2_ref(mwi_msg, -1);
+					ao2_ref(iface, -1);
+					return NULL;
+				}
+				mwi_msg->cause[i] = (char) c;
+			}
 
 			mwi_msg->cause[sizeof(mwi_msg->cause) - 1] = '\0';
 

-- 
To view, visit https://gerrit.asterisk.org/7579
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I59a5e6ef3e7d9e848bec1f4b40cb73321bc7956a
Gerrit-Change-Number: 7579
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171215/15156700/attachment.html>


More information about the asterisk-code-review mailing list