summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Wilson <twilson@digium.com>2012-01-11 19:19:35 +0000
committerTerry Wilson <twilson@digium.com>2012-01-11 19:19:35 +0000
commit9748f19e969b33387836d5a6958c2e3211057732 (patch)
treea1334fc387d748ce8d2d7e3b559c542f9f706472
parent47a55ad6522c5ed023b357519ea9d27a0421912e (diff)
Always treat arguments to get_by_name_cb as strings
Initially, support was left in for the old style of searching, even though it wasn't actually used. In the case of name_len != 0, the OBJ_KEY flag isn't passed because we aren't matching on a full key and therefor can't use the hash function to optimize. The code left in to support the old way of searching unfortunately treated a prefix search like this as though an ast_channel struct was passed as an arg and caused a crash. This patch also adds needed parentheses around some matching conditions. (closes issue ASTERISK-19182) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@350365 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--main/channel.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/main/channel.c b/main/channel.c
index 100b77f79..cc675af97 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1420,7 +1420,7 @@ struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
static int ast_channel_by_name_cb(void *obj, void *arg, void *data, int flags)
{
struct ast_channel *chan = obj;
- const char *name = (flags & OBJ_KEY) ? arg : ast_channel_name((struct ast_channel *)arg);
+ const char *name = arg;
size_t name_len = *(size_t *)data;
int ret = CMP_MATCH;
@@ -1430,7 +1430,8 @@ static int ast_channel_by_name_cb(void *obj, void *arg, void *data, int flags)
}
ast_channel_lock(chan);
- if (!name_len && (strcasecmp(ast_channel_name(chan), name) || (name_len && strncasecmp(ast_channel_name(chan), name, name_len)))) {
+
+ if ((!name_len && strcasecmp(ast_channel_name(chan), name)) || (name_len && strncasecmp(ast_channel_name(chan), name, name_len))) {
ret = 0; /* name match failed, keep looking */
}
ast_channel_unlock(chan);
@@ -1473,8 +1474,8 @@ static int ast_channel_by_uniqueid_cb(void *obj, void *arg, void *data, int flag
}
ast_channel_lock(chan);
- if (!name_len && (strcasecmp(chan->uniqueid, uniqueid) ||
- (name_len && strncasecmp(chan->uniqueid, uniqueid, name_len)))) {
+ if ((!name_len && strcasecmp(chan->uniqueid, uniqueid)) ||
+ (name_len && strncasecmp(chan->uniqueid, uniqueid, name_len))) {
ret = 0;
}
ast_channel_unlock(chan);