From 721026ff37c96823dceff4fcdb72b96ffe5641ad Mon Sep 17 00:00:00 2001
From: Naveen Albert <asterisk@phreaknet.org>
Date: Mon, 15 Nov 2021 19:02:40 +0000
Subject: [PATCH] app_morsecode: Fix deadlock

Fixes a deadlock in app_morsecode caused by locking
the channel twice when reading variables from the
channel. The duplicate lock is simply removed.

ASTERISK-29744 #close

Change-Id: I204000701f123361d7f85e0498fedc90243c75e4
---
 apps/app_morsecode.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/apps/app_morsecode.c b/apps/app_morsecode.c
index 995eb70a1e..f9b211920b 100644
--- a/apps/app_morsecode.c
+++ b/apps/app_morsecode.c
@@ -197,14 +197,12 @@ static int morsecode_exec(struct ast_channel *chan, const char *data)
 	}
 
 	/* Use variable MORSETONE, if set (else 800) */
-	ast_channel_lock(chan);
 	tonec = pbx_builtin_getvar_helper(chan, "MORSETONE");
 	if (ast_strlen_zero(tonec) || (sscanf(tonec, "%30d", &tone) != 1)) {
 		tone = 800;
 	}
 
 	/* Use variable MORSESPACETONE, if set (else 0) */
-
 	toneb = pbx_builtin_getvar_helper(chan, "MORSESPACETONE");
 	if (ast_strlen_zero(toneb) || (sscanf(toneb, "%30d", &toneoff) != 1)) {
 		toneoff = 0;
@@ -216,8 +214,8 @@ static int morsecode_exec(struct ast_channel *chan, const char *data)
 		codetype = "INTERNATIONAL";
 	}
 
+	ast_channel_unlock(chan);
 	if (!strcmp(codetype, "AMERICAN")) {
-		ast_channel_unlock(chan);
 		for (digit = data; *digit; digit++) {
 			const char *dahdit;
 			digit2 = *digit;
@@ -252,7 +250,6 @@ static int morsecode_exec(struct ast_channel *chan, const char *data)
 				break;
 		}
 	} else { /* International */
-		ast_channel_unlock(chan);
 		for (digit = data; *digit; digit++) {
 			const char *dahdit;
 			digit2 = *digit;
-- 
GitLab