From 62a44e621f39812464b3687c7b09e7dcbe78dea6 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 12 Feb 2007 18:13:14 +0000 Subject: [PATCH] some more protection from passing around and printing null values, we are now initializing null's passed to switch_caller_profile_new as blank strings in the caller profile, if your using any caller profile values in if's, please use !switch_strlen_zero() in your check. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4203 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_utils.h | 7 +++ .../endpoints/mod_portaudio/mod_portaudio.c | 2 +- src/switch_caller.c | 48 +++++++++---------- src/switch_ivr.c | 4 +- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index a67a3ceb72..0a4fa62277 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -199,6 +199,13 @@ switch_mutex_unlock(obj->flag_mutex); */ #define switch_strlen_zero(s) (!s || *s == '\0') +/*! + \brief Make a null string a blank string instead + \param s the string to test + \return the original string or blank string. +*/ +#define switch_str_nil(s) (s ? s : "") + /*! \brief Wait a desired number of microseconds and yield the CPU */ diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c index 6d31a63c6d..c87e728bb2 100644 --- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c +++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c @@ -849,7 +849,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (outbound_profile) { char name[128]; - char *id = outbound_profile->caller_id_number ? outbound_profile->caller_id_number : "na"; + char *id = !switch_strlen_zero(outbound_profile->caller_id_number) ? outbound_profile->caller_id_number : "na"; snprintf(name, sizeof(name), "PortAudio/%s", id); switch_channel_set_name(channel, name); diff --git a/src/switch_caller.c b/src/switch_caller.c index 4a5062618d..ec96741c31 100644 --- a/src/switch_caller.c +++ b/src/switch_caller.c @@ -53,17 +53,17 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memor if (!context) { context = "default"; } - profile->username = switch_core_strdup(pool, username); - profile->dialplan = switch_core_strdup(pool, dialplan); - profile->caller_id_name = switch_core_strdup(pool, caller_id_name); - profile->caller_id_number = switch_core_strdup(pool, caller_id_number); - profile->network_addr = switch_core_strdup(pool, network_addr); - profile->ani = switch_core_strdup(pool, ani); - profile->aniii = switch_core_strdup(pool, aniii); - profile->rdnis = switch_core_strdup(pool, rdnis); - profile->source = switch_core_strdup(pool, source); - profile->context = switch_core_strdup(pool, context); - profile->destination_number = switch_core_strdup(pool, destination_number); + profile->username = switch_core_strdup(pool, switch_str_nil(username)); + profile->dialplan = switch_core_strdup(pool, switch_str_nil(dialplan)); + profile->caller_id_name = switch_core_strdup(pool, switch_str_nil(caller_id_name)); + profile->caller_id_number = switch_core_strdup(pool, switch_str_nil(caller_id_number)); + profile->network_addr = switch_core_strdup(pool, switch_str_nil(network_addr)); + profile->ani = switch_core_strdup(pool, switch_str_nil(ani)); + profile->aniii = switch_core_strdup(pool, switch_str_nil(aniii)); + profile->rdnis = switch_core_strdup(pool, switch_str_nil(rdnis)); + profile->source = switch_core_strdup(pool, switch_str_nil(source)); + profile->context = switch_core_strdup(pool, switch_str_nil(context)); + profile->destination_number = switch_core_strdup(pool, switch_str_nil(destination_number)); switch_set_flag(profile, SWITCH_CPF_SCREEN); } @@ -145,55 +145,55 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_ char header_name[1024]; - if (caller_profile->username) { + if (!switch_strlen_zero(caller_profile->username)) { snprintf(header_name, sizeof(header_name), "%s-Username", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->username); } - if (caller_profile->dialplan) { + if (!switch_strlen_zero(caller_profile->dialplan)) { snprintf(header_name, sizeof(header_name), "%s-Dialplan", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->dialplan); } - if (caller_profile->caller_id_name) { + if (!switch_strlen_zero(caller_profile->caller_id_name)) { snprintf(header_name, sizeof(header_name), "%s-Caller-ID-Name", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->caller_id_name); } - if (caller_profile->caller_id_number) { + if (!switch_strlen_zero(caller_profile->caller_id_number)) { snprintf(header_name, sizeof(header_name), "%s-Caller-ID-Number", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->caller_id_number); } - if (caller_profile->network_addr) { + if (!switch_strlen_zero(caller_profile->network_addr)) { snprintf(header_name, sizeof(header_name), "%s-Network-Addr", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->network_addr); } - if (caller_profile->ani) { + if (!switch_strlen_zero(caller_profile->ani)) { snprintf(header_name, sizeof(header_name), "%s-ANI", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->ani); } - if (caller_profile->aniii) { + if (!switch_strlen_zero(caller_profile->aniii)) { snprintf(header_name, sizeof(header_name), "%s-ANI-II", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->aniii); } - if (caller_profile->destination_number) { + if (!switch_strlen_zero(caller_profile->destination_number)) { snprintf(header_name, sizeof(header_name), "%s-Destination-Number", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->destination_number); } - if (caller_profile->uuid) { + if (!switch_strlen_zero(caller_profile->uuid)) { snprintf(header_name, sizeof(header_name), "%s-Unique-ID", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->uuid); } - if (caller_profile->source) { + if (!switch_strlen_zero(caller_profile->source)) { snprintf(header_name, sizeof(header_name), "%s-Source", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->source); } - if (caller_profile->context) { + if (!switch_strlen_zero(caller_profile->context)) { snprintf(header_name, sizeof(header_name), "%s-Context", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->context); } - if (caller_profile->rdnis) { + if (!switch_strlen_zero(caller_profile->rdnis)) { snprintf(header_name, sizeof(header_name), "%s-RDNIS", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->rdnis); } - if (caller_profile->chan_name) { + if (!switch_strlen_zero(caller_profile->chan_name)) { snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->chan_name); } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index b3d745b3d3..3c764278d9 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -3642,13 +3642,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_ new_profile = switch_caller_profile_clone(session, profile); new_profile->destination_number = switch_core_session_strdup(session, extension); - if (dialplan) { + if (!switch_strlen_zero(dialplan)) { new_profile->dialplan = switch_core_session_strdup(session, dialplan); } else { dialplan = new_profile->dialplan; } - if (context) { + if (!switch_strlen_zero(context)) { new_profile->context = switch_core_session_strdup(session, context); } else { context = new_profile->context;