<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10239">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_voicemail:  Fix stack overrun in append_mailbox<br><br>The append_mailbox function wasn't calculating the correct length<br>to pass to ast_alloca and it wasn't handling the case where context<br>might be empty.<br><br>Found by the Address Sanitizer.<br><br>Change-Id: I7eb51c7bd18a7a8dbdba261462a95cc69e84f161<br>---<br>M apps/app_voicemail.c<br>1 file changed, 16 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c</span><br><span>index c5afb32..46b759a 100644</span><br><span>--- a/apps/app_voicemail.c</span><br><span>+++ b/apps/app_voicemail.c</span><br><span>@@ -810,11 +810,16 @@</span><br><span>      unsigned char iobuf[BASEMAXINLINE];</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define MAX_VM_MBOX_ID_LEN (AST_MAX_EXTENSION)</span><br><span style="color: hsl(120, 100%, 40%);">+#define MAX_VM_CONTEXT_LEN (AST_MAX_CONTEXT)</span><br><span style="color: hsl(120, 100%, 40%);">+/* MAX_VM_MAILBOX_LEN allows enough room for the '@' and NULL terminator */</span><br><span style="color: hsl(120, 100%, 40%);">+#define MAX_VM_MAILBOX_LEN (MAX_VM_MBOX_ID_LEN + MAX_VM_CONTEXT_LEN)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Structure for linked list of users</span><br><span>  * Use ast_vm_user_destroy() to free one of these structures. */</span><br><span> struct ast_vm_user {</span><br><span style="color: hsl(0, 100%, 40%);">-  char context[AST_MAX_CONTEXT];   /*!< Voicemail context */</span><br><span style="color: hsl(0, 100%, 40%);">-   char mailbox[AST_MAX_EXTENSION]; /*!< Mailbox id, unique within vm context */</span><br><span style="color: hsl(120, 100%, 40%);">+      char context[MAX_VM_CONTEXT_LEN];/*!< Voicemail context */</span><br><span style="color: hsl(120, 100%, 40%);">+ char mailbox[MAX_VM_MBOX_ID_LEN];/*!< Mailbox id, unique within vm context */</span><br><span>     char password[80];               /*!< Secret pin code, numbers only */</span><br><span>    char fullname[80];               /*!< Full name, for directory app */</span><br><span>     char *email;                     /*!< E-mail address */</span><br><span>@@ -12305,23 +12310,21 @@</span><br><span> {</span><br><span>  size_t len;</span><br><span>  struct poll_state *poll_state;</span><br><span style="color: hsl(0, 100%, 40%);">-  char *mailbox;</span><br><span style="color: hsl(120, 100%, 40%);">+        char mailbox_full[MAX_VM_MAILBOX_LEN];</span><br><span> </span><br><span>   if (ast_strlen_zero(vmu->mailbox)) {</span><br><span>              ast_log(LOG_ERROR, "Mailbox can't be empty\n");</span><br><span>                return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   len = sizeof(vmu->mailbox) + sizeof(vmu->context) + sizeof('@') + 1;</span><br><span style="color: hsl(0, 100%, 40%);">-      mailbox = ast_alloca(len);</span><br><span style="color: hsl(0, 100%, 40%);">-      len = snprintf(mailbox, len, "%s%s%s",</span><br><span style="color: hsl(120, 100%, 40%);">+      len = snprintf(mailbox_full, MAX_VM_MAILBOX_LEN, "%s%s%s",</span><br><span>                 vmu->mailbox,</span><br><span>             ast_strlen_zero(vmu->context) ? "" : "@",</span><br><span>             vmu->context);</span><br><span> </span><br><span>        len++; /* For NULL terminator */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    poll_state = ao2_find(poll_list, mailbox, OBJ_SEARCH_KEY);</span><br><span style="color: hsl(120, 100%, 40%);">+    poll_state = ao2_find(poll_list, mailbox_full, OBJ_SEARCH_KEY);</span><br><span>      if (poll_state) {</span><br><span>            poll_state->marked_used = 1;</span><br><span>              ao2_ref(poll_state, -1);</span><br><span>@@ -12333,7 +12336,7 @@</span><br><span>   if (!poll_state) {</span><br><span>           return -1;</span><br><span>   }</span><br><span style="color: hsl(0, 100%, 40%);">-       strcpy(poll_state->mailbox, mailbox); /* Safe */</span><br><span style="color: hsl(120, 100%, 40%);">+   strcpy(poll_state->mailbox, mailbox_full); /* Safe */</span><br><span>     poll_state->marked_used = 1;</span><br><span> </span><br><span>  ao2_link_flags(poll_list, poll_state, OBJ_NOLOCK);</span><br><span>@@ -12398,7 +12401,7 @@</span><br><span>         char *stringp;</span><br><span>       char *s;</span><br><span>     struct ast_vm_user *vmu;</span><br><span style="color: hsl(0, 100%, 40%);">-        char *mailbox_full;</span><br><span style="color: hsl(120, 100%, 40%);">+   char mailbox_full[MAX_VM_MAILBOX_LEN];</span><br><span>       int new = 0, old = 0, urgent = 0;</span><br><span>    char secretfn[PATH_MAX] = "";</span><br><span> </span><br><span>@@ -12437,10 +12440,10 @@</span><br><span>              read_password_from_file(secretfn, vmu->password, sizeof(vmu->password));</span><br><span>       }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   mailbox_full = ast_alloca(strlen(box) + strlen(context) + 1);</span><br><span style="color: hsl(0, 100%, 40%);">-   strcpy(mailbox_full, box);</span><br><span style="color: hsl(0, 100%, 40%);">-      strcat(mailbox_full, "@");</span><br><span style="color: hsl(0, 100%, 40%);">-    strcat(mailbox_full, context);</span><br><span style="color: hsl(120, 100%, 40%);">+        snprintf(mailbox_full, MAX_VM_MAILBOX_LEN, "%s%s%s",</span><br><span style="color: hsl(120, 100%, 40%);">+                box,</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_strlen_zero(context) ? "" : "@",</span><br><span style="color: hsl(120, 100%, 40%);">+              context);</span><br><span> </span><br><span>        inboxcount2(mailbox_full, &urgent, &new, &old);</span><br><span> #ifdef IMAP_STORAGE</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10239">change 10239</a>. To unsubscribe, or for help writing mail filters, 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/10239"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I7eb51c7bd18a7a8dbdba261462a95cc69e84f161 </div>
<div style="display:none"> Gerrit-Change-Number: 10239 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>