]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_event_multicast] Few fixes
authorTomasz Ostrowski <43222462+tomek-o@users.noreply.github.com>
Mon, 27 Mar 2023 17:23:07 +0000 (19:23 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Mar 2023 17:23:07 +0000 (20:23 +0300)
* [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

src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c

index 1ebf5cb7fed1dd0ccb0bdb7bae49b6b46d82fcd2..2a52ca077890241392dc0b7aabd8f3a602650356 100644 (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;