From 8e604e8a945eb402f5cf318676aa72df76748057 Mon Sep 17 00:00:00 2001 From: Tomasz Ostrowski <43222462+tomek-o@users.noreply.github.com> Date: Mon, 27 Mar 2023 19:23:07 +0200 Subject: [PATCH] [mod_event_multicast] Few fixes * [mod_event_multicast] Fix crash / invalid pointer dereference * [mod_event_multicast] Check current number of addresses before zeroing memory on init * [mod_event_multicast] Fix condition checking number of addresses on init * [mod_event_multicast] Fix addresses zeroing on init * [mod_event_multicast] Reorder memset and assert after malloc --- .../mod_event_multicast/mod_event_multicast.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index 1ebf5cb7fe..2a52ca0778 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -293,13 +293,13 @@ static switch_status_t initialize_sockets(switch_xml_t input_cfg) char *host_string; char ipv6_first_octet[3]; - memset(&globals.dst_sockaddrs[globals.num_dst_addrs].sockaddr, 0, sizeof(dst_sockaddr_t)); - - if (globals.num_dst_addrs > MAX_DST_HOSTS) { + if (globals.num_dst_addrs >= MAX_DST_HOSTS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot add destination address: %s, exceeded maximum of %d\n", dst_hosts[i], MAX_DST_HOSTS); continue; } + memset(&globals.dst_sockaddrs[globals.num_dst_addrs], 0, sizeof(dst_sockaddr_t)); + if (switch_sockaddr_info_get(&globals.dst_sockaddrs[globals.num_dst_addrs].sockaddr, dst_hosts[i], SWITCH_UNSPEC, globals.port, 0, module_pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find address: %s\n", dst_hosts[i]); switch_goto_status(SWITCH_STATUS_TERM, fail); @@ -627,8 +627,8 @@ static void event_handler(switch_event_t *event) len = strlen(packet) + strlen((char *) MAGIC); #endif buf = malloc(len + 1); - memset(buf, 0, len + 1); switch_assert(buf); + memset(buf, 0, len + 1); #ifdef HAVE_OPENSSL if (globals.psk) { @@ -777,7 +777,11 @@ static switch_status_t process_packet(char* packet, size_t len) switch_url_decode(val); switch_snprintf(tmpname, sizeof(tmpname), "Orig-%s", var); switch_event_add_header_string(local_event, SWITCH_STACK_BOTTOM, tmpname, val); - var = term + 1; + if (term) { + var = term + 1; + } else { + var = NULL; + } } else { /* This should be our magic packet, done processing incoming headers */ break;