FS-7397: fix segfault due to memory corruption on using mod_translate app. The session pool was being freed incorrectly after using the app instead of when the session pool was destroyed

This commit is contained in:
Michael Jerris 2016-06-07 12:25:30 -05:00
parent b2e0bdac91
commit 2409c20c73
1 changed files with 27 additions and 47 deletions

View File

@ -230,44 +230,25 @@ SWITCH_STANDARD_APP(translate_app_function)
char *argv[32] = { 0 }; char *argv[32] = { 0 };
char *mydata = NULL; char *mydata = NULL;
char *translated = NULL; char *translated = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_memory_pool_t *pool = NULL;
switch_event_t *event = NULL;
switch_assert(session); if (zstr(data)) {
return;
if (!(mydata = switch_core_session_strdup(session, data))) {
goto end;
} }
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { mydata = switch_core_session_strdup(session, data);
char *areacode = switch_core_get_variable("default_areacode");
if (session) { argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
pool = switch_core_session_get_pool(session);
} else {
switch_core_new_memory_pool(&pool);
switch_event_create(&event, SWITCH_EVENT_MESSAGE);
if (zstr(areacode)) { if (!argc) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "no default_areacode set, using default of 777\n"); return;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "areacode", "777");
} else {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "areacode", areacode);
}
}
translate_number(argv[0], argv[1], &translated, session, event, NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Translated: %s\n", translated);
switch_channel_set_variable_var_check(channel, "translated", translated, SWITCH_FALSE);
} }
end: translate_number(argv[0], argv[1], &translated, session, NULL, NULL);
if (pool) {
switch_core_destroy_memory_pool(&pool); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Translated: %s\n", translated);
}
switch_channel_set_variable_var_check(channel, "translated", translated, SWITCH_FALSE);
return; return;
} }
@ -279,7 +260,6 @@ SWITCH_STANDARD_DIALPLAN(translate_dialplan_hunt)
char *translated_cid_num = NULL; char *translated_cid_num = NULL;
char *translate_profile = NULL; char *translate_profile = NULL;
char *areacode = NULL; char *areacode = NULL;
switch_event_t *event = NULL;
if (!caller_profile) { if (!caller_profile) {
if (!(caller_profile = switch_channel_get_caller_profile(channel))) { if (!(caller_profile = switch_channel_get_caller_profile(channel))) {
@ -292,16 +272,20 @@ SWITCH_STANDARD_DIALPLAN(translate_dialplan_hunt)
caller_profile->caller_id_name, caller_profile->caller_id_number, caller_profile->destination_number); caller_profile->caller_id_name, caller_profile->caller_id_number, caller_profile->destination_number);
if ((translate_profile = (char *) switch_channel_get_variable(channel, "translate_profile"))) { if ((translate_profile = (char *) switch_channel_get_variable(channel, "translate_profile"))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "using translate_profile variable [%s] for translate profile\n", translate_profile); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"using translate_profile variable [%s] for translate profile\n", translate_profile);
} else if ((translate_profile = (char *) switch_channel_get_variable(channel, "country"))) { } else if ((translate_profile = (char *) switch_channel_get_variable(channel, "country"))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "using country variable [%s] for translate profile\n", translate_profile); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"using country variable [%s] for translate profile\n", translate_profile);
} else if ((translate_profile = (char *) switch_channel_get_variable(channel, "default_country"))) { } else if ((translate_profile = (char *) switch_channel_get_variable(channel, "default_country"))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "using default_country variable [%s] for translate profile\n", translate_profile); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"using default_country variable [%s] for translate profile\n", translate_profile);
} else { } else {
translate_profile = "US"; translate_profile = "US";
} }
areacode = (char *) switch_channel_get_variable(channel, "areacode"); areacode = (char *) switch_channel_get_variable(channel, "areacode");
if (zstr(areacode)) { if (zstr(areacode)) {
areacode = (char *) switch_channel_get_variable(channel, "default_areacode"); areacode = (char *) switch_channel_get_variable(channel, "default_areacode");
if (!zstr(areacode)) { if (!zstr(areacode)) {
@ -309,8 +293,8 @@ SWITCH_STANDARD_DIALPLAN(translate_dialplan_hunt)
} }
} }
translate_number((char *) caller_profile->destination_number, translate_profile, &translated_dest, session, event, NULL); translate_number((char *) caller_profile->destination_number, translate_profile, &translated_dest, session, NULL, NULL);
translate_number((char *) caller_profile->caller_id_number, translate_profile, &translated_cid_num, session, event, NULL); translate_number((char *) caller_profile->caller_id_number, translate_profile, &translated_cid_num, session, NULL, NULL);
/* maybe we should translate ani/aniii here too? */ /* maybe we should translate ani/aniii here too? */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO,
"Profile: [%s] Translated Destination: [%s] Translated CID: [%s]\n", translate_profile, translated_dest, translated_cid_num); "Profile: [%s] Translated Destination: [%s] Translated CID: [%s]\n", translate_profile, translated_dest, translated_cid_num);
@ -338,8 +322,10 @@ SWITCH_STANDARD_API(translate_function)
int argc = 0; int argc = 0;
if (zstr(cmd)) { if (zstr(cmd)) {
goto usage; stream->write_function(stream, "USAGE: %s\n", TRANSLATE_SYNTAX);
return SWITCH_STATUS_SUCCESS;
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s\n", cmd); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s\n", cmd);
mydata = strdup(cmd); mydata = strdup(cmd);
@ -365,18 +351,12 @@ SWITCH_STANDARD_API(translate_function)
} }
free(mydata); free(mydata);
end:
if (!session) { if (pool) {
if (pool) { switch_core_destroy_memory_pool(&pool);
switch_core_destroy_memory_pool(&pool);
}
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
usage:
stream->write_function(stream, "USAGE: %s\n", TRANSLATE_SYNTAX);
goto end;
} }
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_translate_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_translate_shutdown)