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
This commit is contained in:
Terry Wilson
2012-01-11 19:19:35 +00:00
parent 47a55ad652
commit 9748f19e96

View File

@@ -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);