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

Sean Bright asteriskteam at digium.com
Fri Dec 3 11:08:35 CST 2021


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


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/16/17616/1

diff --git a/main/channel.c b/main/channel.c
index 546f4f8..36afb7f 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1426,17 +1426,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/+/17616
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I88eadc748e9c6996fc17467b0a05881bbfd00bce
Gerrit-Change-Number: 17616
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/20211203/ae61db42/attachment.html>


More information about the asterisk-code-review mailing list