From c0c552de2c59a5142d3067dd26d73a08369c9932 Mon Sep 17 00:00:00 2001 From: Jonathan Rose <jrose@digium.com> Date: Fri, 16 Nov 2012 19:59:45 +0000 Subject: [PATCH] monitor: prevent attempts to move/remove recordings skipped with 'i' and 'o'. The i and o options for monitor skip the input and output sides of a recording respectively. This patch addresses a problem in those options when monitor is called without specifying a specific filename where monitor will try to move the recording that was skipped. Since this usually doesn't exist when these options are used, it would produce a warning when it does this in most cases, but it is conceivable that there are use cases where this could result in moving/removing a file unintentionally. (closes issue ASTERISK-20641) Reported by: Jonathan Rose Review: https://reviewboard.asterisk.org/r/2190/ ........ Merged revisions 376389 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 376390 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@376391 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/res_monitor.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/res/res_monitor.c b/res/res_monitor.c index 9aca24a0da..02a2cd2310 100644 --- a/res/res_monitor.c +++ b/res/res_monitor.c @@ -451,24 +451,28 @@ int AST_OPTIONAL_API_NAME(ast_monitor_stop)(struct ast_channel *chan, int need_l } if (ast_channel_monitor(chan)->filename_changed && !ast_strlen_zero(ast_channel_monitor(chan)->filename_base)) { - if (ast_fileexists(ast_channel_monitor(chan)->read_filename,NULL,NULL) > 0) { - snprintf(filename, FILENAME_MAX, "%s-in", ast_channel_monitor(chan)->filename_base); - if (ast_fileexists(filename, NULL, NULL) > 0) { - ast_filedelete(filename, NULL); + if (ast_channel_monitor(chan)->read_stream) { + if (ast_fileexists(ast_channel_monitor(chan)->read_filename,NULL,NULL) > 0) { + snprintf(filename, FILENAME_MAX, "%s-in", ast_channel_monitor(chan)->filename_base); + if (ast_fileexists(filename, NULL, NULL) > 0) { + ast_filedelete(filename, NULL); + } + ast_filerename(ast_channel_monitor(chan)->read_filename, filename, ast_channel_monitor(chan)->format); + } else { + ast_log(LOG_WARNING, "File %s not found\n", ast_channel_monitor(chan)->read_filename); } - ast_filerename(ast_channel_monitor(chan)->read_filename, filename, ast_channel_monitor(chan)->format); - } else { - ast_log(LOG_WARNING, "File %s not found\n", ast_channel_monitor(chan)->read_filename); } - if (ast_fileexists(ast_channel_monitor(chan)->write_filename,NULL,NULL) > 0) { - snprintf(filename, FILENAME_MAX, "%s-out", ast_channel_monitor(chan)->filename_base); - if (ast_fileexists(filename, NULL, NULL) > 0) { - ast_filedelete(filename, NULL); + if (ast_channel_monitor(chan)->write_stream) { + if (ast_fileexists(ast_channel_monitor(chan)->write_filename,NULL,NULL) > 0) { + snprintf(filename, FILENAME_MAX, "%s-out", ast_channel_monitor(chan)->filename_base); + if (ast_fileexists(filename, NULL, NULL) > 0) { + ast_filedelete(filename, NULL); + } + ast_filerename(ast_channel_monitor(chan)->write_filename, filename, ast_channel_monitor(chan)->format); + } else { + ast_log(LOG_WARNING, "File %s not found\n", ast_channel_monitor(chan)->write_filename); } - ast_filerename(ast_channel_monitor(chan)->write_filename, filename, ast_channel_monitor(chan)->format); - } else { - ast_log(LOG_WARNING, "File %s not found\n", ast_channel_monitor(chan)->write_filename); } } -- GitLab