Merge pull request #442 from signalwire/mod_cidlookup

[mod_cidlookup] Fix dereference of null pointer and optimize use of pool's memory avoiding double-allocations.
This commit is contained in:
Andrey Volk 2020-02-27 00:06:27 +04:00 committed by GitHub
commit 776ae387ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -545,9 +545,6 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
cid_data_t *cidtmp = NULL;
switch_bool_t save_cache = SWITCH_FALSE;
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
number = string_digitsonly(pool, num);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller_id_number", number);
@ -555,6 +552,8 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
if (globals.odbc_dsn && globals.sql) {
name = do_db_lookup(pool, event, number, globals.sql);
if (name) {
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
cid->name = name;
cid->src = "phone_database";
goto done;
@ -578,6 +577,11 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
}
}
if (!cid) {
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
}
if (!skipurl && globals.url) {
url_query = switch_event_expand_headers(event, globals.url);
do_lookup_url(pool, event, &name, url_query, NULL, NULL, 0);
@ -593,10 +597,6 @@ static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event,
}
done:
if (!cid) {
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
}
/* append area if we can */
if (!cid->area && !skipcitystate && strlen(number) == 11 && number[0] == '1' && globals.odbc_dsn && globals.citystate_sql) {