]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7397: fix segfault due to memory corruption on using mod_translate app. The sessi...
authorMichael Jerris <mike@jerris.com>
Tue, 7 Jun 2016 17:25:30 +0000 (12:25 -0500)
committerMichael Jerris <mike@jerris.com>
Tue, 7 Jun 2016 17:25:30 +0000 (12:25 -0500)
src/mod/applications/mod_translate/mod_translate.c

index b3f9e96ad5c6530309ffd2d1d58bcbd64497f62c..5fbf8fbe32e5e97677d0d6dd3af1d6f0167b0379 100644 (file)
@@ -230,44 +230,25 @@ SWITCH_STANDARD_APP(translate_app_function)
        char *argv[32] = { 0 };
        char *mydata = NULL;
        char *translated = NULL;
-       switch_channel_t *channel = switch_core_session_get_channel(session);
-       switch_memory_pool_t *pool = NULL;
-       switch_event_t *event = NULL;
-
-       switch_assert(session);
+       switch_channel_t *channel  = switch_core_session_get_channel(session);
 
-       if (!(mydata = switch_core_session_strdup(session, data))) {
-               goto end;
+       if (zstr(data)) {
+               return;
        }
 
-       if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
-               char *areacode = switch_core_get_variable("default_areacode");
-
-               if (session) {
-                       pool = switch_core_session_get_pool(session);
-               } else {
-                       switch_core_new_memory_pool(&pool);
-                       switch_event_create(&event, SWITCH_EVENT_MESSAGE);
+       mydata = switch_core_session_strdup(session, data);
 
-                       if (zstr(areacode)) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "no default_areacode set, using default of 777\n");
-                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "areacode", "777");
-                       } else {
-                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "areacode", areacode);
-                       }
-               }
+       argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
-               translate_number(argv[0], argv[1], &translated, session, event, NULL);
+       if (!argc) {
+               return;
+       }
 
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Translated: %s\n", translated);
+       translate_number(argv[0], argv[1], &translated, session, NULL, NULL);
 
-               switch_channel_set_variable_var_check(channel, "translated", translated, SWITCH_FALSE);
-       }
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Translated: %s\n", translated);
 
-end:
-       if (pool) {
-               switch_core_destroy_memory_pool(&pool);
-       }
+       switch_channel_set_variable_var_check(channel, "translated", translated, SWITCH_FALSE);
 
        return;
 }
@@ -279,7 +260,6 @@ SWITCH_STANDARD_DIALPLAN(translate_dialplan_hunt)
        char *translated_cid_num = NULL;
        char *translate_profile = NULL;
        char *areacode = NULL;
-       switch_event_t *event = NULL;
 
        if (!caller_profile) {
                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);
 
        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"))) {
-               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"))) {
-               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 {
                translate_profile = "US";
        }
 
        areacode = (char *) switch_channel_get_variable(channel, "areacode");
+
        if (zstr(areacode)) {
                areacode = (char *) switch_channel_get_variable(channel, "default_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->caller_id_number, translate_profile, &translated_cid_num, 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, NULL, NULL);
        /* maybe we should translate ani/aniii here too? */
        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);
@@ -338,8 +322,10 @@ SWITCH_STANDARD_API(translate_function)
        int argc = 0;
 
        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);
 
        mydata = strdup(cmd);
@@ -365,18 +351,12 @@ SWITCH_STANDARD_API(translate_function)
        }
 
        free(mydata);
-end:
-       if (!session) {
-               if (pool) {
-                       switch_core_destroy_memory_pool(&pool);
-               }
+
+       if (pool) {
+               switch_core_destroy_memory_pool(&pool);
        }
 
        return SWITCH_STATUS_SUCCESS;
-
-usage:
-       stream->write_function(stream, "USAGE: %s\n", TRANSLATE_SYNTAX);
-       goto end;
 }
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_translate_shutdown)