From 660159dff146661e6a7e2910a988d457c8f8863a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 8 Dec 2006 16:31:58 +0000 Subject: [PATCH] add extra input checking for valid input on some api's and functions. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3583 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 14 +++++++------- src/mod/applications/mod_dptools/mod_dptools.c | 17 +++++++++-------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 4a9b8c0511..c2353a8e7e 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -162,7 +162,7 @@ static switch_status_t load_function(char *mod, switch_core_session_t *session, return SWITCH_STATUS_SUCCESS; } -static switch_status_t reload_function(char *mod, switch_core_session_t *session, switch_stream_handle_t *stream) +static switch_status_t reload_function(char *args, switch_core_session_t *session, switch_stream_handle_t *stream) { const char *err; switch_xml_t xml_root; @@ -214,7 +214,7 @@ static switch_status_t transfer_function(char *cmd, switch_core_session_t *isess argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if (argc < 2 || argc > 4) { + if (switch_strlen_zero(cmd) || argc < 2 || argc > 4) { stream->write_function(stream, "USAGE: %s\n", transfer_api_interface.syntax); } else { char *uuid = argv[0]; @@ -252,7 +252,7 @@ static switch_status_t uuid_media_function(char *cmd, switch_core_session_t *ise argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if (argc < 1) { + if (switch_strlen_zero(cmd) || argc < 1) { stream->write_function(stream, "USAGE: %s\n", media_api_interface.syntax); } else { if (!strcmp(argv[0], "off")) { @@ -284,7 +284,7 @@ static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if (argc < 2) { + if (switch_strlen_zero(cmd) || argc < 2) { stream->write_function(stream, "USAGE: %s\n", broadcast_api_interface.syntax); } else { switch_media_flag_t flags = SMF_NONE; @@ -320,7 +320,7 @@ static switch_status_t uuid_hold_function(char *cmd, switch_core_session_t *ises argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if (argc < 1) { + if (switch_strlen_zero(cmd) || argc < 1) { stream->write_function(stream, "USAGE: %s\n", hold_api_interface.syntax); } else { if (!strcmp(argv[0], "off")) { @@ -350,7 +350,7 @@ static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *is argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if (argc != 2) { + if (switch_strlen_zero(cmd) || argc != 2) { stream->write_function(stream, "USAGE: %s\n", uuid_bridge_api_interface.syntax); } else { if (switch_ivr_uuid_bridge(argv[0], argv[1]) != SWITCH_STATUS_SUCCESS) { @@ -373,7 +373,7 @@ static switch_status_t pause_function(char *cmd, switch_core_session_t *isession argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); - if (argc < 2) { + if (switch_strlen_zero(cmd) || argc < 2) { stream->write_function(stream, "USAGE: %s\n", pause_api_interface.syntax); } else { char *uuid = argv[0]; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 83f8033ad5..f9ee910ad9 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -43,7 +43,7 @@ static void detect_speech_function(switch_core_session_t *session, char *data) int argc; char *lbuf = NULL; - if ((lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { + if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { if (!strcasecmp(argv[0], "grammar") && argc >= 1) { switch_ivr_detect_speech_load_grammar(session, argv[1], argv[2]); } else if (!strcasecmp(argv[0], "nogrammar")) { @@ -77,7 +77,7 @@ static void transfer_function(switch_core_session_t *session, char *data) char *argv[4] = {0}; char *mydata; - if ((mydata = switch_core_session_strdup(session, data))) { + if (data && (mydata = switch_core_session_strdup(session, data))) { if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 1) { switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]); } else { @@ -144,7 +144,7 @@ static void log_function(switch_core_session_t *session, char *data) channel = switch_core_session_get_channel(session); assert(channel != NULL); - if ((level = strdup(data))) { + if (data && (level = strdup(data))) { switch_event_types_t etype = SWITCH_LOG_DEBUG; if ((log_str = strchr(level, ' '))) { @@ -220,7 +220,7 @@ static void strftime_function(switch_core_session_t *session, char *data) int argc; char *lbuf; - if ((lbuf = switch_core_session_strdup(session, data))&&(argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) { + if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) { switch_size_t retsize; switch_time_exp_t tm; char date[80] = ""; @@ -238,12 +238,13 @@ static void strftime_function(switch_core_session_t *session, char *data) static switch_status_t strftime_api_function(char *fmt, switch_core_session_t *session, switch_stream_handle_t *stream) { + switch_size_t retsize; switch_time_exp_t tm; char date[80] = ""; switch_time_exp_lt(&tm, switch_time_now()); - switch_strftime(date, &retsize, sizeof(date), fmt, &tm); + switch_strftime(date, &retsize, sizeof(date), fmt ? fmt : "%Y-%m-%d %T", &tm); stream->write_function(stream, date); return SWITCH_STATUS_SUCCESS; @@ -290,7 +291,7 @@ static switch_status_t chat_api_function(char *fmt, switch_core_session_t *sessi char *lbuf, *argv[4]; int argc = 0; - if ((lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) { + if (fmt && (lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) { switch_chat_interface_t *ci; if ((ci = switch_loadable_module_get_chat_interface(argv[0]))) { @@ -324,9 +325,9 @@ static switch_ivr_action_t menu_handler(switch_ivr_menu_t *menu, char *param, ch static void ivr_application_function(switch_core_session_t *session, char *data) { switch_channel_t *channel = switch_core_session_get_channel(session); - char *params = switch_core_session_strdup(session,data); + char *params; - if (channel != NULL && params != NULL) { + if (channel && data && (params = switch_core_session_strdup(session,data))) { switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL; // Open the config from the xml registry