From cdb4810f8aa78d71723ad2ba84996be93042edd6 Mon Sep 17 00:00:00 2001
From: Mike Jerris <mike@signalwire.com>
Date: Thu, 13 Aug 2020 20:45:58 +0400
Subject: [PATCH] [Build-System] Remove mod_freetdm from spec file, fix compile
 errors on CentOS

---
 freeswitch.spec                               | 76 +------------------
 src/mod/applications/mod_avmd/mod_avmd.c      |  1 +
 .../mod_cdr_mongodb/driver/src/mongo.c        | 13 ++--
 .../mod_erlang_event/ei_helpers.c             |  2 +-
 4 files changed, 12 insertions(+), 80 deletions(-)

diff --git a/freeswitch.spec b/freeswitch.spec
index e8bb6d64cf..7bf9774602 100644
--- a/freeswitch.spec
+++ b/freeswitch.spec
@@ -4,7 +4,7 @@
 #
 # includes module(s): freeswitch-devel freeswitch-codec-passthru-amr freeswitch-codec-passthru-amrwb freeswitch-codec-passthru-g729 
 #                     freeswitch-codec-passthru-g7231 freeswitch-lua freeswitch-mariadb freeswitch-pgsql freeswitch-perl freeswitch-python freeswitch-v8 freeswitch-signalwire
-#                     freeswitch-lan-de freeswitch-lang-en freeswitch-lang-fr freeswitch-lang-hu freeswitch-lang-ru freeswitch-freetdm
+#                     freeswitch-lan-de freeswitch-lang-en freeswitch-lang-fr freeswitch-lang-hu freeswitch-lang-ru
 #		      and others
 #
 # Initial Version Copyright (C) 2007 Peter Nixon and Michal Bielicki, All Rights Reserved.
@@ -959,52 +959,6 @@ Requires:       %{name} = %{version}-%{release}
 %description endpoint-rtc
 Verto protocol support for FreeSWITCH open source telephony platform.
 
-%package freetdm
-Summary:	Provides a unified interface to hardware TDM cards and ss7 stacks for FreeSWITCH
-Group:		System/Libraries
-Requires:        %{name} = %{version}-%{release}
-
-%description freetdm
-FreeTDM
-
-%if %{build_sng_isdn}
-
-%package freetdm-sng-isdn
-Summary:	Sangoma ISDN Module for FreeTDM
-Group:		System/Libraries
-Requires:       %{name} = %{version}-%{release}
-Requires:       %{name}-freetdm = %{version}-%{release}
-Requires: wanpipe 
-Requires: libsng_isdn 
-BuildRequires: wanpipe 
-BuildRequires: libsng_isdn 
-
-%description freetdm-sng-isdn
-Sangoma ISDN Module for freetdm
-
-%endif
-
-%if %{build_sng_ss7}
-
-%package freetdm-sng-ss7
-Summary:	Provides a unified interface to hardware TDM cards and ss7 stacks for FreeSWITCH, Sangoma SS7 Module
-Group:		System/Libraries
-Requires:        %{name} = %{version}-%{release}
-Requires:       %{name}-freetdm = %{version}-%{release}
-Requires: wanpipe 
-Requires: libsng_ss7 
-BuildRequires: wanpipe 
-BuildRequires: libsng_ss7 
-%if 0%{?fedora_version} >= 8 || 0%{?rhel} >= 6
-Requires: openssl098e
-BuildRequires: openssl098e
-%endif
-
-%description freetdm-sng-ss7
-Sangoma SMG-SS7 drivers for FreeTDM
-
-%endif
-
 ######################################################################################################################
 #				FreeSWITCH Event Handler Modules
 ######################################################################################################################
@@ -1567,7 +1521,7 @@ DIRECTORIES_MODULES=""
 #						Endpoints
 #
 ######################################################################################################################
-ENDPOINTS_MODULES="endpoints/mod_dingaling ../../libs/freetdm/mod_freetdm \
+ENDPOINTS_MODULES="endpoints/mod_dingaling \
 			endpoints/mod_loopback endpoints/mod_portaudio endpoints/mod_rtmp \
 			endpoints/mod_skinny endpoints/mod_verto endpoints/mod_rtc endpoints/mod_sofia"
 
@@ -2351,32 +2305,6 @@ fi
 %files endpoint-rtc
 %{MODINSTDIR}/mod_rtc.so*
 
-######################################################################################################################
-#
-#						FreeTDM Module for TDM Interaction
-#
-######################################################################################################################
-%files freetdm
-%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/tones.conf
-%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/autoload_configs/freetdm.conf.xml
-%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/pika.conf
-%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/freetdm.conf
-%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/wanpipe.conf
-%config(noreplace) %attr(0640, freeswitch, daemon) %{sysconfdir}/zt.conf
-%{LIBDIR}/libfreetdm.so*
-%{MODINSTDIR}/mod_freetdm.so*
-%{MODINSTDIR}/ftmod_skel*.so*
-%{MODINSTDIR}/ftmod_[a-r,t-z]*.so*
-
-%if %{build_sng_ss7}
-%files freetdm-sng-ss7
-%{MODINSTDIR}/ftmod_sangoma_ss7.so*
-%endif
-
-%if %{build_sng_isdn}
-%files freetdm-sng-isdn
-%{MODINSTDIR}/ftmod_sangoma_isdn.so*
-%endif
 
 ######################################################################################################################
 #
diff --git a/src/mod/applications/mod_avmd/mod_avmd.c b/src/mod/applications/mod_avmd/mod_avmd.c
index 4b95e1a5c1..a7a59d9289 100644
--- a/src/mod/applications/mod_avmd/mod_avmd.c
+++ b/src/mod/applications/mod_avmd/mod_avmd.c
@@ -1340,6 +1340,7 @@ static switch_status_t avmd_parse_cmd_data(avmd_session_t *s, const char *cmd_da
             /* iterate over params, check if they mean something to us, set */
             idx = 0;
             while (idx < argc) {
+                switch_assert(argv[idx]);
                 status = avmd_parse_cmd_data_one_entry(argv[idx], &settings);
                 if (status != SWITCH_STATUS_SUCCESS) {
                     switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(s->session), SWITCH_LOG_ERROR,
diff --git a/src/mod/event_handlers/mod_cdr_mongodb/driver/src/mongo.c b/src/mod/event_handlers/mod_cdr_mongodb/driver/src/mongo.c
index 51da18d078..77870b3dc2 100644
--- a/src/mod/event_handlers/mod_cdr_mongodb/driver/src/mongo.c
+++ b/src/mod/event_handlers/mod_cdr_mongodb/driver/src/mongo.c
@@ -406,7 +406,7 @@ MONGO_EXPORT int mongo_connect( mongo *conn , const char *host, int port ) {
     mongo_init( conn );
 
     conn->primary = bson_malloc( sizeof( mongo_host_port ) );
-    strncpy( conn->primary->host, host, strlen( host ) + 1 );
+    strncpy( conn->primary->host, host, sizeof(conn->primary->host) - 1 );
     conn->primary->port = port;
     conn->primary->next = NULL;
 
@@ -438,7 +438,7 @@ static void mongo_replset_add_node( mongo_host_port **list, const char *host, in
     mongo_host_port *host_port = bson_malloc( sizeof( mongo_host_port ) );
     host_port->port = port;
     host_port->next = NULL;
-    strncpy( host_port->host, host, strlen( host ) + 1 );
+    strncpy( host_port->host, host, sizeof(host_port->host) - 1 );
 
     if( *list == NULL )
         *list = host_port;
@@ -618,7 +618,7 @@ MONGO_EXPORT int mongo_replset_connect( mongo *conn ) {
 
                 /* Primary found, so return. */
                 else if( conn->replset->primary_connected ) {
-                    strncpy( conn->primary->host, node->host, strlen( node->host ) + 1 );
+                    snprintf( conn->primary->host, sizeof(conn->primary->host), "%s", node->host );
                     conn->primary->port = node->port;
                     return MONGO_OK;
                 }
@@ -1246,10 +1246,13 @@ MONGO_EXPORT int mongo_find_one( mongo *conn, const char *ns, const bson *query,
 }
 
 MONGO_EXPORT void mongo_cursor_init( mongo_cursor *cursor, mongo *conn, const char *ns ) {
+    size_t len = strlen(ns) + 1;
     memset( cursor, 0, sizeof( mongo_cursor ) );
     cursor->conn = conn;
-    cursor->ns = ( const char * )bson_malloc( strlen( ns ) + 1 );
-    strncpy( ( char * )cursor->ns, ns, strlen( ns ) + 1 );
+    cursor->ns = ( const char * )bson_malloc( len );
+    if (cursor->ns) {
+        strncpy((char *)cursor->ns, ns, len);
+    }
     cursor->current.data = NULL;
 }
 
diff --git a/src/mod/event_handlers/mod_erlang_event/ei_helpers.c b/src/mod/event_handlers/mod_erlang_event/ei_helpers.c
index cf3a6aca31..6472180a2e 100644
--- a/src/mod/event_handlers/mod_erlang_event/ei_helpers.c
+++ b/src/mod/event_handlers/mod_erlang_event/ei_helpers.c
@@ -202,7 +202,7 @@ int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref * ref, char *module,
 void ei_init_ref(ei_cnode * ec, erlang_ref * ref)
 {
 	memset(ref, 0, sizeof(*ref));	/* zero out the struct */
-	snprintf(ref->node, MAXATOMLEN, "%s", ec->thisnodename);
+	snprintf(ref->node, MAXATOMLEN + 1, "%s", ec->thisnodename);
 
 	switch_mutex_lock(mod_erlang_event_globals.ref_mutex);
 	mod_erlang_event_globals.reference0++;