From 06d8cec790d74bfbd374db9b10bfec83207a71ba Mon Sep 17 00:00:00 2001
From: Ghislain MARY <ghislain.mary@belledonne-communications.com>
Date: Thu, 22 Nov 2012 11:36:29 +0100
Subject: [PATCH] Add checks to prevent crashes.

The getReceiverInterarrivalJitter() function may be called before the
used audio codec is known in case of early media, so test that the
payload type is valid before using it.
---
 coreapi/linphonecore_jni.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc
index 55041b17a8..03d5c0df0a 100644
--- a/coreapi/linphonecore_jni.cc
+++ b/coreapi/linphonecore_jni.cc
@@ -1372,6 +1372,8 @@ extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getSenderInterarr
 		pt = linphone_call_params_get_used_audio_codec(params);
 	else
 		pt = linphone_call_params_get_used_video_codec(params);
+	if (!pt || (pt->clock_rate == 0))
+		return (jfloat)0.0;
 	return (jfloat)((float)report_block_get_interarrival_jitter(srb) / (float)pt->clock_rate);
 }
 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverInterarrivalJitter(JNIEnv *env, jobject thiz, jlong stats_ptr, jlong call_ptr) {
@@ -1399,6 +1401,8 @@ extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getReceiverIntera
 		pt = linphone_call_params_get_used_audio_codec(params);
 	else
 		pt = linphone_call_params_get_used_video_codec(params);
+	if (!pt || (pt->clock_rate == 0))
+		return (jfloat)0.0;
 	return (jfloat)((float)report_block_get_interarrival_jitter(rrb) / (float)pt->clock_rate);
 }
 extern "C" jfloat Java_org_linphone_core_LinphoneCallStatsImpl_getRoundTripDelay(JNIEnv *env, jobject thiz, jlong stats_ptr) {
-- 
GitLab