Skip to content

Commit 64a764c

Browse files
InterLinked1Friendly Automation
authored andcommitted
res_calendar: Prevent assertion if event ends in past.
res_calendar will trigger an assertion currently if the ending time is calculated to be in the past. Unlike the reminder and start times, however, there is currently no check to catch non-positive times and set them to 1. As a result, if we get a negative value by happenstance, this can cause a crash. To prevent the assertion from begin triggered, we now use the same logic as the reminder and start events to catch this issue before it can cause a problem. ASTERISK-29981 #close Change-Id: Idfb3204d195f350d2575fb4bc72a54a597d6e93c
1 parent bae8092 commit 64a764c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

res/res_calendar.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,15 @@ static int schedule_calendar_event(struct ast_calendar *cal, struct ast_calendar
998998
if (!cmp_event || old_event->end != event->end) {
999999
changed = 1;
10001000
devstate_sched_end = (event->end - now.tv_sec) * 1000;
1001-
ast_mutex_lock(&refreshlock);
1002-
AST_SCHED_REPLACE(old_event->bs_end_sched, sched, devstate_sched_end, calendar_devstate_change, old_event);
1003-
ast_mutex_unlock(&refreshlock);
1004-
ast_debug(3, "Calendar bs_end event notification scheduled to happen in %ld ms\n", (long) devstate_sched_end);
1001+
1002+
if (devstate_sched_end <= 0) { /* if we let this slip by, Asterisk will assert */
1003+
ast_log(LOG_WARNING, "Whoops! Event end notification scheduled in the past: %ld ms\n", (long) devstate_sched_end);
1004+
} else {
1005+
ast_mutex_lock(&refreshlock);
1006+
AST_SCHED_REPLACE(old_event->bs_end_sched, sched, devstate_sched_end, calendar_devstate_change, old_event);
1007+
ast_mutex_unlock(&refreshlock);
1008+
ast_debug(3, "Calendar bs_end event notification scheduled to happen in %ld ms\n", (long) devstate_sched_end);
1009+
}
10051010
}
10061011

10071012
if (changed) {

0 commit comments

Comments
 (0)