]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 372555 via svnmerge from
authorAutomerge script <automerge@asterisk.org>
Fri, 7 Sep 2012 02:24:26 +0000 (02:24 +0000)
committerAutomerge script <automerge@asterisk.org>
Fri, 7 Sep 2012 02:24:26 +0000 (02:24 +0000)
file:///srv/subversion/repos/asterisk/branches/10

................
  r372555 | mjordan | 2012-09-06 21:11:46 -0500 (Thu, 06 Sep 2012) | 22 lines

  Fix file descriptor leak and pointer scope issue in MiniVM when sending mail

  When MiniVM sends an e-mail and it has the volgain option set, it will spawn
  sox in a separate process to handle the manipulation of the sound file.  In
  doing so, it creates a temporary file.  There are two problems here:
    1) The file descriptor returned from mkstemp is leaked
    2) The finalfilename character pointer points to a buffer that loses scope
       once volgain processing is finished.

  Note that in r316265, Russell fixed some gcc warnings by using the return
  value of the mkstemp call.  A warning was placed in minivm that the file
  descriptor was going to be leaked.  This patch reverts that change, as it
  handles the leak and 'uses' the file descriptor returned from mkstemp.

  (closes issue ASTERISK-17133)
  Reported by: Tzafrir Cohen
  patches:
    minivm_18501_demo.diff uploaded by Tzafrir Cohen (license #5035)
  ........

  Merged revisions 372554 from http://svn.asterisk.org/svn/asterisk/branches/1.8
................

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10-digiumphones@372580 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_minivm.c

index c977f917ca08a3fabdc8e24e2892d7d3fc35cdf3..d40246cdcb9d95d8865009857991a1e07f79bdcd 100644 (file)
@@ -1229,6 +1229,7 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu
        char dur[PATH_MAX];
        char tmp[80] = "/tmp/astmail-XXXXXX";
        char tmp2[PATH_MAX];
+       char newtmp[PATH_MAX]; /* Only used with volgain */
        struct timeval now;
        struct ast_tm tm;
        struct minivm_zone *the_zone = NULL;
@@ -1268,26 +1269,21 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu
 
        /* If we have a gain option, process it now with sox */
        if (type == MVM_MESSAGE_EMAIL && (vmu->volgain < -.001 || vmu->volgain > .001) ) {
-               char newtmp[PATH_MAX];
                char tmpcmd[PATH_MAX];
                int tmpfd;
 
-               /**
-                * XXX
-                * /bug tmpfd is a leaked fd.  The file is also never unlinked.
-                *      See app_voicemail.c for how the code works there that
-                *      doesn't have this bug.
-                */
-
                ast_copy_string(newtmp, "/tmp/XXXXXX", sizeof(newtmp));
                ast_debug(3, "newtmp: %s\n", newtmp);
                tmpfd = mkstemp(newtmp);
-               if (tmpfd > -1) {
-                       snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, filename, format, newtmp, format);
-                       ast_safe_system(tmpcmd);
-                       finalfilename = newtmp;
-                       ast_debug(3, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", filename, format, vmu->volgain, vmu->username);
+               if (tmpfd < 0) {
+                       ast_log(LOG_WARNING, "Failed to create temporary file for volgain: %d\n", errno);
+                       return -1;
                }
+               snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, filename, format, newtmp, format);
+               ast_safe_system(tmpcmd);
+               close(tmpfd);
+               finalfilename = newtmp;
+               ast_debug(3, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", filename, format, vmu->volgain, vmu->username);
        } else {
                finalfilename = ast_strdupa(filename);
        }