[Asterisk-code-review] pjsip/config transport: Check pjproject version at runtime f... (asterisk[13])

George Joseph asteriskteam at digium.com
Sat Dec 12 11:15:38 CST 2015


George Joseph has uploaded a new change for review.

  https://gerrit.asterisk.org/1806

Change subject: pjsip/config_transport: Check pjproject version at runtime for async ops
......................................................................

pjsip/config_transport: Check pjproject version at runtime for async ops

pjproject < 2.5.0 will segfault on a tls transport if async_operations
is greater than 1.  A runtime version check has been added to throw
an error if the version is < 2.5.0 and async_operations > 1.

To assist in the check, a new api "ast_compare_versions" was added
to utils which compares 2 major.minor.patch.extra version strings.

ASTERISK-25615 #close

Change-Id: I8e88bb49cbcfbca88d9de705496d6f6a8c938a98
Reported-by: George Joseph
Tested-by: George Joseph
---
M include/asterisk/utils.h
M main/utils.c
M res/res_pjsip/config_transport.c
3 files changed, 37 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/06/1806/1

diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 832500c..cfb78c0 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -1099,4 +1099,16 @@
  */
 int ast_file_is_readable(const char *filename);
 
+/*
+ * \brief Compare 2 major.minor.patch.extra version strings.
+ * \since 13.7.0
+ *
+ * \param version1.
+ * \param version2.
+ * \return -1 if version 1 < version 2.
+ * \return 0 if version 1 = version 2.
+ * \return 1 if version 1 > version 2.
+ */
+int ast_compare_versions(const char *version1, const char *version2);
+
 #endif /* _ASTERISK_UTILS_H */
diff --git a/main/utils.c b/main/utils.c
index 3eeafed..82e3701 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2949,3 +2949,26 @@
 	return 1;
 #endif
 }
+
+int ast_compare_versions(const char *version1, const char *version2)
+{
+	u_int64_t major[2] = { 0 };
+	u_int64_t minor[2] = { 0 };
+	u_int64_t patch[2] = { 0 };
+	u_int64_t extra[2] = { 0 };
+	u_int64_t v1, v2;
+
+	sscanf(version1, "%lu.%lu.%lu.%lu", &major[0], &minor[0], &patch[0], &extra[0]);
+	sscanf(version2, "%lu.%lu.%lu.%lu", &major[1], &minor[1], &patch[1], &extra[1]);
+
+	v1 = major[0] << 48 | minor[0] << 32 | patch[0] << 16 | extra[0];
+	v2 = major[1] << 48 | minor[1] << 32 | patch[1] << 16 | extra[1];
+
+	if (v1 < v2) {
+		return -1;
+	} else if (v1 > v2) {
+		return 1;
+	} else {
+		return 0;
+	}
+}
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index d8ece15..840824b 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -217,11 +217,8 @@
 
 		res = pjsip_tcp_transport_start3(ast_sip_get_pjsip_endpoint(), &cfg, &transport->state->factory);
 	} else if (transport->type == AST_TRANSPORT_TLS) {
-		/* The following check is a work-around for ASTERISK-25615.
-		 * When that issue is resolved in upstream pjproject, this check can be removed.
-		 */
-		if (transport->async_operations > 1) {
-			ast_log(LOG_ERROR, "Transport: %s: When protocol=tls, async_operations can't be > 1 (ASTERISK-25615)\n",
+		if (transport->async_operations > 1 && ast_compare_versions(pj_get_version(), "2.5.0") < 0) {
+			ast_log(LOG_ERROR, "Transport: %s: When protocol=tls and pjproject version < 2.5.0, async_operations can't be > 1\n",
 					ast_sorcery_object_get_id(obj));
 			return -1;
 		}

-- 
To view, visit https://gerrit.asterisk.org/1806
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e88bb49cbcfbca88d9de705496d6f6a8c938a98
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: George Joseph <george.joseph at fairview5.com>



More information about the asterisk-code-review mailing list