[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
This commit is contained in:
Tomasz Ostrowski 2023-03-27 19:23:07 +02:00 committed by GitHub
parent 2c36dcdd50
commit 8e604e8a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -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;