[Asterisk-code-review] channel: Short-circuit ast_channel_get_by_name() on empty arg (asterisk[16])

Sean Bright asteriskteam at digium.com
Tue Nov 30 14:28:32 CST 2021


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17590 )


Change subject: channel: Short-circuit ast_channel_get_by_name() on empty arg
......................................................................

channel: Short-circuit ast_channel_get_by_name() on empty arg

We know that passing a NULL or empty argument to
ast_channel_get_by_name() will never result in a matching channel and
will always result in an error being emitted, so just short-circuit
out in that case.

ASTERISK-28219 #close

Change-Id: I88eadc748e9c6996fc17467b0a05881bbfd00bce
---
M main/channel.c
1 file changed, 5 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/90/17590/1

diff --git a/main/channel.c b/main/channel.c
index 8505b1d..de5e39f 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1449,17 +1449,17 @@
 	struct ast_channel *chan;
 	char *l_name = (char *) name;
 
+	if (ast_strlen_zero(l_name)) {
+		/* We didn't have a name to search for so quit. */
+		return NULL;
+	}
+
 	chan = ast_channel_callback(ast_channel_by_name_cb, l_name, &name_len,
 		(name_len == 0) /* optimize if it is a complete name match */ ? OBJ_KEY : 0);
 	if (chan) {
 		return chan;
 	}
 
-	if (ast_strlen_zero(l_name)) {
-		/* We didn't have a name to search for so quit. */
-		return NULL;
-	}
-
 	/* Now try a search for uniqueid. */
 	return ast_channel_callback(ast_channel_by_uniqueid_cb, l_name, &name_len, 0);
 }

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17590
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I88eadc748e9c6996fc17467b0a05881bbfd00bce
Gerrit-Change-Number: 17590
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211130/0e221bbc/attachment.html>


More information about the asterisk-code-review mailing list