From: Jonathan Rose Date: Fri, 16 Nov 2012 19:41:55 +0000 (+0000) Subject: monitor: prevent attempts to move/remove recordings skipped with 'i' and 'o'. X-Git-Tag: 10.12.0-rc1~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=071720e4e1775649617e02067acd7908f6ec7e71;p=thirdparty%2Fasterisk.git 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 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@376390 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/res/res_monitor.c b/res/res_monitor.c index 1c0565cee5..711a54b915 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 (chan->monitor->filename_changed && !ast_strlen_zero(chan->monitor->filename_base)) { - if (ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0) { - snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base); - if (ast_fileexists(filename, NULL, NULL) > 0) { - ast_filedelete(filename, NULL); + if (chan->monitor->read_stream) { + if (ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0) { + snprintf(filename, FILENAME_MAX, "%s-in", chan->monitor->filename_base); + if (ast_fileexists(filename, NULL, NULL) > 0) { + ast_filedelete(filename, NULL); + } + ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format); + } else { + ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename); } - ast_filerename(chan->monitor->read_filename, filename, chan->monitor->format); - } else { - ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->read_filename); } - if (ast_fileexists(chan->monitor->write_filename,NULL,NULL) > 0) { - snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base); - if (ast_fileexists(filename, NULL, NULL) > 0) { - ast_filedelete(filename, NULL); + if (chan->monitor->write_stream) { + if (ast_fileexists(chan->monitor->write_filename,NULL,NULL) > 0) { + snprintf(filename, FILENAME_MAX, "%s-out", chan->monitor->filename_base); + if (ast_fileexists(filename, NULL, NULL) > 0) { + ast_filedelete(filename, NULL); + } + ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format); + } else { + ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename); } - ast_filerename(chan->monitor->write_filename, filename, chan->monitor->format); - } else { - ast_log(LOG_WARNING, "File %s not found\n", chan->monitor->write_filename); } }