From 37a79ead36b8123e5c6ac3c42a7031397a2ed747 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 3 Feb 2017 09:47:14 -0500 Subject: [PATCH] TT#10350 fix kamailio rtpengine module segfault Change-Id: I91d551a68ebaa28af0c1c13f55b67983cd11cdbb --- debian/patches/series | 1 + .../sipwise/rtpengine-sockets-list-fix.patch | 126 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 debian/patches/sipwise/rtpengine-sockets-list-fix.patch diff --git a/debian/patches/series b/debian/patches/series index 578eff3d6..033abe832 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -40,3 +40,4 @@ sipwise/sca-use-To-header-if-in-dialog-as-target.patch sipwise/sca-fix-sca_call_info_update-params.patch sipwise/sca-use-onhold_bflag-value-only-when-set.patch ## +sipwise/rtpengine-sockets-list-fix.patch diff --git a/debian/patches/sipwise/rtpengine-sockets-list-fix.patch b/debian/patches/sipwise/rtpengine-sockets-list-fix.patch new file mode 100644 index 000000000..9f109b316 --- /dev/null +++ b/debian/patches/sipwise/rtpengine-sockets-list-fix.patch @@ -0,0 +1,126 @@ +--- a/modules/rtpengine/rtpengine.c ++++ b/modules/rtpengine/rtpengine.c +@@ -195,7 +195,7 @@ + static struct rtpp_node *select_rtpp_node_old(str, str, int, enum rtpe_operation); + static struct rtpp_node *select_rtpp_node(str, str, int, struct rtpp_node **, int, enum rtpe_operation); + static int is_queried_node(struct rtpp_node *, struct rtpp_node **, int); +-static int build_rtpp_socks(unsigned int current_rtpp_no); ++static int build_rtpp_socks(); + static char *send_rtpp_command(struct rtpp_node *, bencode_item_t *, int *); + static int get_extra_id(struct sip_msg* msg, str *id_str); + +@@ -1069,6 +1069,9 @@ + str rtpp_url; + str snode, sattr, svalue; + ++ if (build_rtpp_socks()) ++ return init_mi_tree(400, MI_DB_ERR, MI_DB_ERR_LEN); ++ + found = MI_FOUND_NONE; + found_rtpp_disabled = 0; + found_rtpp = NULL; +@@ -1413,6 +1416,9 @@ + str rtpp_url; + str snode, sattr, svalue; + ++ if (build_rtpp_socks()) ++ return init_mi_tree(400, MI_DB_ERR, MI_DB_ERR_LEN); ++ + found = 0; + found_rtpp_disabled = 0; + found_rtpp = NULL; +@@ -1577,7 +1583,6 @@ + mi_reload_rtp_proxy(struct mi_root* cmd_tree, void* param) + { + struct mi_root *root = NULL; +- unsigned int current_rtpp_no; + + if (rtpp_db_url.s == NULL) { + // no database +@@ -1595,13 +1600,7 @@ + return 0; + } + } else { +- lock_get(rtpp_no_lock); +- current_rtpp_no = *rtpp_no; +- lock_release(rtpp_no_lock); +- +- if (rtpp_socks_size != current_rtpp_no) { +- build_rtpp_socks(current_rtpp_no); +- } ++ build_rtpp_socks(); + + // success reloading from database + root = init_mi_tree(200, MI_DB_OK, MI_DB_OK_LEN); +@@ -1796,16 +1795,24 @@ + return 0; + } + +-static int build_rtpp_socks(unsigned int current_rtpp_no) { ++static int build_rtpp_socks() { + int n, i; + char *cp; + struct addrinfo hints, *res; + struct rtpp_set *rtpp_list; + struct rtpp_node *pnode; ++ unsigned int current_rtpp_no; + #ifdef IP_MTU_DISCOVER + int ip_mtu_discover = IP_PMTUDISC_DONT; + #endif + ++ lock_get(rtpp_no_lock); ++ current_rtpp_no = *rtpp_no; ++ lock_release(rtpp_no_lock); ++ ++ if (current_rtpp_no == rtpp_socks_size) ++ return 0; ++ + // close current sockets + for (i = 0; i < rtpp_socks_size; i++) { + if (rtpp_socks[i] >= 0) { +@@ -1921,16 +1928,6 @@ + + mypid = getpid(); + +- lock_get(rtpp_no_lock); +- rtpp_socks_size = *rtpp_no; +- lock_release(rtpp_no_lock); +- +- rtpp_socks = (int*)pkg_malloc(sizeof(int)*(rtpp_socks_size)); +- if (!rtpp_socks) { +- return -1; +- } +- memset(rtpp_socks, -1, sizeof(int)*(rtpp_socks_size)); +- + // vector of pointers to queried nodes + queried_nodes_ptr = (struct rtpp_node**)pkg_malloc(queried_nodes_limit * sizeof(struct rtpp_node*)); + if (!queried_nodes_ptr) { +@@ -1940,9 +1937,8 @@ + memset(queried_nodes_ptr, 0, queried_nodes_limit * sizeof(struct rtpp_node*)); + + /* Iterate known RTP proxies - create sockets */ +- if (rtpp_socks_size) { +- build_rtpp_socks(rtpp_socks_size); +- } ++ if (build_rtpp_socks()) ++ return -1; + + return 0; + } +@@ -2867,15 +2863,8 @@ + select_rtpp_node(str callid, str viabranch, int do_test, struct rtpp_node **queried_nodes_ptr, int queried_nodes, enum rtpe_operation op) + { + struct rtpp_node *node = NULL; +- unsigned int current_rtpp_no; + +- lock_get(rtpp_no_lock); +- current_rtpp_no = *rtpp_no; +- lock_release(rtpp_no_lock); +- +- if (rtpp_socks_size != current_rtpp_no) { +- build_rtpp_socks(current_rtpp_no); +- } ++ build_rtpp_socks(); + + if (!active_rtpp_set) { + default_rtpp_set = select_rtpp_set(setid_default);