From: Russell Bryant Date: Tue, 13 Sep 2011 07:11:36 +0000 (+0000) Subject: Fix a crash in res_ais. X-Git-Tag: 1.8.8.0-rc1~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f1882731a7251198c44d2ddd0aba062a4cf326c;p=thirdparty%2Fasterisk.git Fix a crash in res_ais. This patch resolves a crash observed in a load testing environment that involved the use of the res_ais module. I observed some crashes where the event delivery callback would get called, but the length parameter incidcating how much data there was to read was 0. The code assumed (with good reason I would think) that if this callback got called, there was an event available to read. However, if the rare case that there's nothing there, catch it and return instead of blowing up. More specifically, the change always ensure that the size of the received event in the cluster is always big enough to be a real ast_event. Review: https://reviewboard.asterisk.org/r/1423/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@335497 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/include/asterisk/event.h b/include/asterisk/event.h index 73f121c97d..90e27b2f6c 100644 --- a/include/asterisk/event.h +++ b/include/asterisk/event.h @@ -743,6 +743,13 @@ void *ast_event_iterator_get_ie_raw(struct ast_event_iterator *iterator); */ uint16_t ast_event_iterator_get_ie_raw_payload_len(struct ast_event_iterator *iterator); +/*! + * \brief Get the minimum length of an ast_event. + * + * \return minimum amount of memory that will be consumed by any ast_event. + */ +size_t ast_event_minimum_length(void); + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/main/event.c b/main/event.c index fad8e66ee7..a62e736376 100644 --- a/main/event.c +++ b/main/event.c @@ -1769,3 +1769,8 @@ int ast_event_init(void) return 0; } + +size_t ast_event_minimum_length(void) +{ + return sizeof(struct ast_event); +} diff --git a/res/ais/evt.c b/res/ais/evt.c index 9438d77408..003a9cca65 100644 --- a/res/ais/evt.c +++ b/res/ais/evt.c @@ -135,6 +135,13 @@ void evt_event_deliver_cb(SaEvtSubscriptionIdT sub_id, return; } + if (event_datalen < ast_event_minimum_length()) { + ast_debug(1, "Ignoring event that's too small. %u < %u\n", + (unsigned int) event_datalen, + (unsigned int) ast_event_minimum_length()); + return; + } + ais_res = saEvtEventDataGet(event_handle, event, &len); if (ais_res != SA_AIS_OK) { ast_log(LOG_ERROR, "Error retrieving event payload: %s\n",