]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Add sanity checking for position resuming. We *have* to make sure that the position...
authorJoshua Colp <jcolp@digium.com>
Wed, 19 Mar 2008 19:11:33 +0000 (19:11 +0000)
committerJoshua Colp <jcolp@digium.com>
Wed, 19 Mar 2008 19:11:33 +0000 (19:11 +0000)
(closes issue #11663)
Reported by: junky

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

res/res_musiconhold.c

index 87b3278974bfdf6a8f788ea4ccdee25452ea6e0f..491eacb8bb1131aed6d0867ff7a06f76345e6a39 100644 (file)
@@ -120,6 +120,7 @@ struct moh_files_state {
        int sample_queue;
        int pos;
        int save_pos;
+       char *save_pos_filename;
 };
 
 #define MOH_QUIET              (1 << 0)
@@ -239,8 +240,8 @@ static int ast_moh_files_next(struct ast_channel *chan)
                return -1;
        }
 
-       /* If a specific file has been saved, use it */
-       if (state->save_pos >= 0) {
+       /* If a specific file has been saved confirm it still exists and that it is still valid */
+       if (state->save_pos >= 0 && state->save_pos < state->class->total_files && state->class->filearray[state->save_pos] == state->save_pos_filename) {
                state->pos = state->save_pos;
                state->save_pos = -1;
        } else if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
@@ -250,11 +251,13 @@ static int ast_moh_files_next(struct ast_channel *chan)
                        if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) > 0)
                                break;
                }
+               state->save_pos = -1;
                state->samples = 0;
        } else {
                /* This is easy, just increment our position and make sure we don't exceed the total file count */
                state->pos++;
                state->pos %= state->class->total_files;
+               state->save_pos = -1;
                state->samples = 0;
        }
 
@@ -265,6 +268,9 @@ static int ast_moh_files_next(struct ast_channel *chan)
                return -1;
        }
 
+       /* Record the pointer to the filename for position resuming later */
+       state->save_pos_filename = state->class->filearray[state->pos];
+
        if (option_debug)
                ast_log(LOG_DEBUG, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]);