<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10238">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, 12 insertions(+), 7 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 c6e501c..b900c5a 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>@@ -12357,7 +12362,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>@@ -12396,10 +12401,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/10238">change 10238</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/10238"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16.0 </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: 10238 </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>