]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
channel: Short-circuit ast_channel_get_by_name() on empty arg.
authorSean Bright <sean.bright@gmail.com>
Tue, 30 Nov 2021 20:16:45 +0000 (15:16 -0500)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Mon, 6 Dec 2021 16:19:42 +0000 (10:19 -0600)
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

main/channel.c

index 546f4f84e6e029e8f6256c134702c2aa6ca6d3aa..36afb7fe1b5db2468ffe0db6074fb780a5ba3880 100644 (file)
@@ -1426,17 +1426,17 @@ struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name
        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);
 }