Fix AMI Monitor action without File header converting channel name into filename.
authorRichard Mudgett <rmudgett@digium.com>
Thu, 16 Feb 2012 18:39:46 +0000 (18:39 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Thu, 16 Feb 2012 18:39:46 +0000 (18:39 +0000)
* Fix potential Solaris crash if Monitor application has a urlbase and no
fname_base option.
........

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

Merged revisions 355575 from http://svn.asterisk.org/svn/asterisk/branches/10

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@355576 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_monitor.c

index e57c68c..b87d0e7 100644 (file)
@@ -333,10 +333,12 @@ int AST_OPTIONAL_API_NAME(ast_monitor_start)(struct ast_channel *chan, const cha
                        seq++;
                        ast_mutex_unlock(&monitorlock);
 
                        seq++;
                        ast_mutex_unlock(&monitorlock);
 
+                       /* Replace all '/' chars from the channel name with '-' chars. */
                        channel_name = ast_strdupa(ast_channel_name(chan));
                        channel_name = ast_strdupa(ast_channel_name(chan));
-                       while ((p = strchr(channel_name, '/'))) {
+                       for (p = channel_name; (p = strchr(p, '/')); ) {
                                *p = '-';
                        }
                                *p = '-';
                        }
+
                        snprintf(monitor->filename_base, FILENAME_MAX, "%s/%d-%s",
                                         ast_config_AST_MONITOR_DIR, (int)time(NULL), channel_name);
                        monitor->filename_changed = 1;
                        snprintf(monitor->filename_base, FILENAME_MAX, "%s/%d-%s",
                                         ast_config_AST_MONITOR_DIR, (int)time(NULL), channel_name);
                        monitor->filename_changed = 1;
@@ -580,7 +582,8 @@ int AST_OPTIONAL_API_NAME(ast_monitor_change_fname)(struct ast_channel *chan, co
                        ast_mkdir(dirname(name), 0777);
                }
 
                        ast_mkdir(dirname(name), 0777);
                }
 
-               /*!\note We cannot just compare filenames, due to symlinks, relative
+               /*!
+                * \note We cannot just compare filenames, due to symlinks, relative
                 * paths, and other possible filesystem issues.  We could use
                 * realpath(3), but its use is discouraged.  However, if we try to
                 * create the same file from two different paths, the second will
                 * paths, and other possible filesystem issues.  We could use
                 * realpath(3), but its use is discouraged.  However, if we try to
                 * create the same file from two different paths, the second will
@@ -639,9 +642,9 @@ int AST_OPTIONAL_API_NAME(ast_monitor_change_fname)(struct ast_channel *chan, co
 */
 static int start_monitor_exec(struct ast_channel *chan, const char *data)
 {
 */
 static int start_monitor_exec(struct ast_channel *chan, const char *data)
 {
-       char *arg = NULL;
-       char *options = NULL;
-       char *delay = NULL;
+       char *arg;
+       char *options;
+       char *delay;
        char *urlprefix = NULL;
        char tmp[256];
        int stream_action = X_REC_IN | X_REC_OUT;
        char *urlprefix = NULL;
        char tmp[256];
        int stream_action = X_REC_IN | X_REC_OUT;
@@ -681,7 +684,7 @@ static int start_monitor_exec(struct ast_channel *chan, const char *data)
                urlprefix = arg;
        }
 
                urlprefix = arg;
        }
 
-       if (urlprefix) {
+       if (!ast_strlen_zero(urlprefix) && !ast_strlen_zero(args.fname_base)) {
                snprintf(tmp, sizeof(tmp), "%s/%s.%s", urlprefix, args.fname_base,
                        ((strcmp(args.format, "gsm")) ? "wav" : "gsm"));
                ast_channel_lock(chan);
                snprintf(tmp, sizeof(tmp), "%s/%s.%s", urlprefix, args.fname_base,
                        ((strcmp(args.format, "gsm")) ? "wav" : "gsm"));
                ast_channel_lock(chan);
@@ -757,12 +760,13 @@ static int start_monitor_action(struct mansession *s, const struct message *m)
        }
 
        if (ast_strlen_zero(fname)) {
        }
 
        if (ast_strlen_zero(fname)) {
-               /* No filename base specified, default to channel name as per CLI */
+               /* No filename specified, default to the channel name. */
                ast_channel_lock(c);
                fname = ast_strdupa(ast_channel_name(c));
                ast_channel_unlock(c);
                ast_channel_lock(c);
                fname = ast_strdupa(ast_channel_name(c));
                ast_channel_unlock(c);
-               /* Channels have the format technology/channel_name - have to replace that /  */
-               if ((d = strchr(fname, '/'))) {
+
+               /* Replace all '/' chars from the channel name with '-' chars. */
+               for (d = (char *) fname; (d = strchr(d, '/')); ) {
                        *d = '-';
                }
        }
                        *d = '-';
                }
        }