aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-06 18:23:36 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-06 18:23:36 +0000
commitcd0b9bcfce2ae3c1723407684a339397e9cc95d0 (patch)
treee7740e844ea4568ac9c6da2e7e72c3454b653dcc
parent487d264c99349c74c2895fcf2313dad878f0b5a8 (diff)
Merged revisions 89037 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r89037 | russell | 2007-11-06 12:20:07 -0600 (Tue, 06 Nov 2007) | 11 lines If someone were to delete the files used by an existing MOH class, and then issue a reload, further use of that class could result in a crash due to dividing by zero. This set of changes fixes up some places to prevent this from happening. (closes issue #10948) Reported by: jcomellas Patches: res_musiconhold_division_by_zero.patch uploaded by jcomellas (license 282) Additional changes added by me. ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@89038 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--res/res_musiconhold.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index dd1304ee4..920c57c80 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -231,6 +231,11 @@ static int ast_moh_files_next(struct ast_channel *chan)
chan->stream = NULL;
}
+ if (!state->class->total_files) {
+ ast_log(LOG_WARNING, "No files available for class '%s'\n", state->class->name);
+ return -1;
+ }
+
/* If a specific file has been saved, use it */
if (state->save_pos >= 0) {
state->pos = state->save_pos;
@@ -320,7 +325,7 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params)
/* initialize */
memset(state, 0, sizeof(*state));
state->class = class;
- if (ast_test_flag(state->class, MOH_RANDOMIZE))
+ if (ast_test_flag(state->class, MOH_RANDOMIZE) && class->total_files)
state->pos = ast_random() % class->total_files;
}
@@ -1291,8 +1296,15 @@ static int init_classes(int reload)
AST_RWLIST_REMOVE_CURRENT(&mohclasses, list);
if (!moh->inuse)
ast_moh_destroy_one(moh);
- } else if (moh->total_files)
- moh_scan_files(moh);
+ } else if (moh->total_files) {
+ if (moh_scan_files(moh)) {
+ ast_log(LOG_WARNING, "No files found for class '%s'\n", moh->name);
+ moh->delete = 1;
+ AST_LIST_REMOVE_CURRENT(&mohclasses, list);
+ if (!moh->inuse)
+ ast_moh_destroy_one(moh);
+ }
+ }
}
AST_RWLIST_TRAVERSE_SAFE_END
AST_RWLIST_UNLOCK(&mohclasses);