<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7580">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">coverity: Fix warnings in res_smdi<br><br>ASTERISK-19657 #close<br>Reported by: Matt Jordan III, Esq.<br><br>Change-Id: I59a5e6ef3e7d9e848bec1f4b40cb73321bc7956a<br>---<br>M res/res_smdi.c<br>1 file changed, 36 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/80/7580/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_smdi.c b/res/res_smdi.c<br>index 0edabb8..054e6aa 100644<br>--- a/res/res_smdi.c<br>+++ b/res/res_smdi.c<br>@@ -586,9 +586,8 @@<br> struct ast_smdi_interface *iface = iface_p;<br> struct ast_smdi_md_message *md_msg;<br> struct ast_smdi_mwi_message *mwi_msg;<br>- char c = '\0';<br> char *cp = NULL;<br>- int i;<br>+ int i, c;<br> int start = 0;<br> <br> /* read an smdi message */<br>@@ -616,7 +615,14 @@<br> <br> /* read the message desk number */<br> for (i = 0; i < sizeof(md_msg->mesg_desk_num) - 1; i++) {<br>- md_msg->mesg_desk_num[i] = fgetc(iface->file);<br>+ c = fgetc(iface->file);<br>+ if (c == EOF) {<br>+ ast_log(LOG_ERROR, "Unexpected EOF while reading MD message\n");<br>+ ao2_ref(md_msg, -1);<br>+ ao2_ref(iface, -1);<br>+ return NULL;<br>+ }<br>+ md_msg->mesg_desk_num[i] = (char) c;<br> ast_debug(1, "Read a '%c'\n", md_msg->mesg_desk_num[i]);<br> }<br> <br>@@ -626,7 +632,14 @@<br> <br> /* read the message desk terminal number */<br> for (i = 0; i < sizeof(md_msg->mesg_desk_term) - 1; i++) {<br>- md_msg->mesg_desk_term[i] = fgetc(iface->file);<br>+ c = fgetc(iface->file);<br>+ if (c == EOF) {<br>+ ast_log(LOG_ERROR, "Unexpected EOF while reading SMDI message\n");<br>+ ao2_ref(md_msg, -1);<br>+ ao2_ref(iface, -1);<br>+ return NULL;<br>+ }<br>+ md_msg->mesg_desk_term[i] = (char) c;<br> ast_debug(1, "Read a '%c'\n", md_msg->mesg_desk_term[i]);<br> }<br> <br>@@ -635,7 +648,14 @@<br> ast_debug(1, "The message desk terminal is '%s'\n", md_msg->mesg_desk_term);<br> <br> /* read the message type */<br>- md_msg->type = fgetc(iface->file);<br>+ c = fgetc(iface->file);<br>+ if (c == EOF) {<br>+ ast_log(LOG_ERROR, "Unexpected EOF while reading SMDI message\n");<br>+ ao2_ref(md_msg, -1);<br>+ ao2_ref(iface, -1);<br>+ return NULL;<br>+ }<br>+ md_msg->type = (char) c;<br> <br> ast_debug(1, "Message type is '%c'\n", md_msg->type);<br> <br>@@ -717,7 +737,7 @@<br> <br> /* discard the 'I' (from 'MWI') */<br> fgetc(iface->file);<br>- <br>+<br> /* read the forwarding station number (may be blank) */<br> cp = &mwi_msg->fwd_st[0];<br> for (i = 0; i < sizeof(mwi_msg->fwd_st) - 1; i++) {<br>@@ -740,8 +760,16 @@<br> ast_copy_string(mwi_msg->name, mwi_msg->fwd_st, sizeof(mwi_msg->name));<br> <br> /* read the mwi failure cause */<br>- for (i = 0; i < sizeof(mwi_msg->cause) - 1; i++)<br>- mwi_msg->cause[i] = fgetc(iface->file);<br>+ for (i = 0; i < sizeof(mwi_msg->cause) - 1; i++) {<br>+ c = fgetc(iface->file);<br>+ if (c == EOF) {<br>+ ast_log(LOG_ERROR, "Unexpected EOF while reading MWI message\n");<br>+ ao2_ref(mwi_msg, -1);<br>+ ao2_ref(iface, -1);<br>+ return NULL;<br>+ }<br>+ mwi_msg->cause[i] = (char) c;<br>+ }<br> <br> mwi_msg->cause[sizeof(mwi_msg->cause) - 1] = '\0';<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7580">change 7580</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7580"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I59a5e6ef3e7d9e848bec1f4b40cb73321bc7956a </div>
<div style="display:none"> Gerrit-Change-Number: 7580 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>