From 6c25cb41367490bff853078e7531513b99e96761 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 30 Dec 2007 00:22:51 +0000 Subject: [PATCH] don't strstr on null/blank strings. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7027 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 4 ++-- src/mod/applications/mod_conference/mod_conference.c | 4 ++-- src/mod/endpoints/mod_portaudio/mod_portaudio.c | 2 +- src/mod/endpoints/mod_sofia/sofia_presence.c | 2 +- src/mod/languages/mod_spidermonkey/mod_spidermonkey.c | 2 +- src/switch_config.c | 2 +- src/switch_ivr_play_say.c | 2 +- src/switch_loadable_module.c | 6 +++--- src/switch_xml.cpp | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index f366b449b1..dbcc14c233 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -50,9 +50,9 @@ SWITCH_BEGIN_EXTERN_C codec->implementation->samples_per_second, \ codec->implementation->microseconds_per_frame / 1000) #ifdef WIN32 -#define switch_is_file_path(file) (*file == '\\' || *(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR)) +#define switch_is_file_path(file) (file && (*file == '\\' || *(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR))) #else -#define switch_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)) +#define switch_is_file_path(file) (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))) #endif SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen); diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 9fde61ec9d..4e2e9edbdb 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -3498,9 +3498,9 @@ switch_status_t conf_api_dispatch(conference_obj_t * conference, switch_stream_h const char *modified_cmdline = cmdline; const char *cmd = conf_api_sub_commands[i].pname; - if ((start_text = strstr(modified_cmdline, cmd))) { + if (!switch_strlen_zero(modified_cmdline) && (start_text = strstr(modified_cmdline, cmd))) { modified_cmdline = start_text + strlen(cmd); - while (modified_cmdline && *modified_cmdline && (*modified_cmdline == ' ' || *modified_cmdline == '\t')) { + while (modified_cmdline && (*modified_cmdline == ' ' || *modified_cmdline == '\t')) { modified_cmdline++; } } diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 8b5590bb1c..2d5a030c69 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -1016,7 +1016,7 @@ static int get_dev_by_name(char *name, int in) if (switch_strlen_zero(name)) { match = 1; - } else if (strstr(pdi->name, name)) { + } else if (pdi && pdi->name && strstr(pdi->name, name)) { match = 1; } diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index b33480938d..54f950833b 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1275,7 +1275,7 @@ void sofia_presence_handle_sip_i_message(int status, const char *subject = "n/a"; char *msg = NULL; - if (sip->sip_content_type) { + if (sip->sip_content_type && !switch_strlen_zero(sip->sip_content_type->c_subtype)) { if (strstr(sip->sip_content_type->c_subtype, "composing")) { return; } diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index 76dbef44f0..f102c336a0 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -1027,7 +1027,7 @@ static switch_status_t load_modules(void) if ((mods = switch_xml_child(cfg, "modules"))) { for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) { const char *val = switch_xml_attr_soft(ld, "module"); - if (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { + if (!switch_strlen_zero(val) && strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); continue; } diff --git a/src/switch_config.c b/src/switch_config.c index d6fbe00d38..cb9db9de45 100644 --- a/src/switch_config.c +++ b/src/switch_config.c @@ -68,7 +68,7 @@ SWITCH_DECLARE(int) switch_config_open_file(switch_config_t * cfg, char *file_pa cfg->path = path; while (switch_config_next_pair(cfg, &var, &val)) { - if ((cfg->sectno != last) && !strcmp(cfg->section, file_path)) { + if (file_path && (cfg->sectno != last) && !strcmp(cfg->section, file_path)) { cfg->lockto = cfg->sectno; return 1; } diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index b083fbc101..8bbc9ba5b2 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -695,7 +695,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess timer_name = switch_channel_get_variable(channel, "timer_name"); - if (!file) { + if (switch_strlen_zero(file)) { status = SWITCH_STATUS_FALSE; goto end; } diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index d1d89b2531..ae73b9e4bf 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -983,7 +983,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() if ((mods = switch_xml_child(cfg, "modules"))) { for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) { const char *val = switch_xml_attr_soft(ld, "module"); - if (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { + if (switch_strlen_zero(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); continue; } @@ -1003,7 +1003,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() if ((mods = switch_xml_child(cfg, "modules"))) { for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) { const char *val = switch_xml_attr_soft(ld, "module"); - if (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { + if (switch_strlen_zero(val) || (strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); continue; } @@ -1043,7 +1043,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() continue; } - if (!strstr(fname, ext) && !strstr(fname, EXT)) { + if (switch_strlen_zero(fname) || (!strstr(fname, ext) && !strstr(fname, EXT))) { continue; } diff --git a/src/switch_xml.cpp b/src/switch_xml.cpp index b9e10e620f..61e143a0a4 100644 --- a/src/switch_xml.cpp +++ b/src/switch_xml.cpp @@ -1402,7 +1402,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key, if (user_name) { - if (strstr(xtra_params, "mailbox")) { + if (!switch_strlen_zero(xtra_params) && strstr(xtra_params, "mailbox")) { if ((*user = switch_xml_find_child(*domain, "user", "mailbox", user_name))) { return SWITCH_STATUS_SUCCESS; }