Index: apps/app_jack.c =================================================================== --- apps/app_jack.c (revision 410669) +++ apps/app_jack.c (working copy) @@ -951,6 +951,11 @@ { int res; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!strcasecmp(value, "on")) res = enable_jack_hook(chan, data); else if (!strcasecmp(value, "off")) Index: apps/app_speech_utils.c =================================================================== --- apps/app_speech_utils.c (revision 410669) +++ apps/app_speech_utils.c (working copy) @@ -284,7 +284,11 @@ { struct ast_speech *speech = NULL; struct ast_datastore *datastore = NULL; - + + if (!chan) { + return NULL; + } + datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); if (datastore == NULL) { return NULL; Index: apps/app_stack.c =================================================================== --- apps/app_stack.c (revision 410669) +++ apps/app_stack.c (working copy) @@ -687,6 +687,11 @@ struct gosub_stack_frame *frame; struct ast_var_t *variables; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); if (!(stack_store = ast_channel_datastore_find(chan, &stack_info, NULL))) { ast_channel_unlock(chan); @@ -721,6 +726,11 @@ struct gosub_stack_list *oldlist; struct gosub_stack_frame *frame; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); if (!(stack_store = ast_channel_datastore_find(chan, &stack_info, NULL))) { ast_log(LOG_ERROR, "Tried to set LOCAL(%s), but we aren't within a Gosub routine\n", var); Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 410669) +++ apps/app_voicemail.c (working copy) @@ -12045,7 +12045,9 @@ } else if (!strncasecmp(arg.attribute, "pager", 5)) { ast_copy_string(buf, vmu->pager, len); } else if (!strncasecmp(arg.attribute, "language", 8)) { - ast_copy_string(buf, S_OR(vmu->language, ast_channel_language(chan)), len); + const char *lang = S_OR(vmu->language, chan ? + ast_channel_language(chan) : defaultlanguage); + ast_copy_string(buf, lang, len); } else if (!strncasecmp(arg.attribute, "locale", 6)) { ast_copy_string(buf, vmu->locale, len); } else if (!strncasecmp(arg.attribute, "tz", 2)) { Index: apps/confbridge/conf_config_parser.c =================================================================== --- apps/confbridge/conf_config_parser.c (revision 410669) +++ apps/confbridge/conf_config_parser.c (working copy) @@ -354,6 +354,11 @@ AST_APP_ARG(option); ); + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + /* parse all the required arguments and make sure they exist. */ if (ast_strlen_zero(data)) { return -1; Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 410669) +++ channels/chan_iax2.c (working copy) @@ -10013,10 +10013,16 @@ static int acf_iaxvar_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { - struct ast_datastore *variablestore = ast_channel_datastore_find(chan, &iax2_variable_datastore_info, NULL); + struct ast_datastore *variablestore; AST_LIST_HEAD(, ast_var_t) *varlist; struct ast_var_t *var; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + + variablestore = ast_channel_datastore_find(chan, &iax2_variable_datastore_info, NULL); if (!variablestore) { *buf = '\0'; return 0; @@ -10036,10 +10042,16 @@ static int acf_iaxvar_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) { - struct ast_datastore *variablestore = ast_channel_datastore_find(chan, &iax2_variable_datastore_info, NULL); + struct ast_datastore *variablestore; AST_LIST_HEAD(, ast_var_t) *varlist; struct ast_var_t *var; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + + variablestore = ast_channel_datastore_find(chan, &iax2_variable_datastore_info, NULL); if (!variablestore) { variablestore = ast_datastore_alloc(&iax2_variable_datastore_info, NULL); if (!variablestore) { @@ -14307,8 +14319,9 @@ /* if our channel, return the IP address of the endpoint of current channel */ if (!strcmp(peername,"CURRENTCHANNEL")) { unsigned short callno; - if (ast_channel_tech(chan) != &iax2_tech) + if (!chan || ast_channel_tech(chan) != &iax2_tech) { return -1; + } callno = PTR_TO_CALLNO(ast_channel_tech_pvt(chan)); ast_copy_string(buf, iaxs[callno]->addr.sin_addr.s_addr ? ast_inet_ntoa(iaxs[callno]->addr.sin_addr) : "", len); return 0; Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 410669) +++ channels/chan_sip.c (working copy) @@ -21985,6 +21985,11 @@ ); int i, number, start = 0; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "This function requires a header name.\n"); return -1; @@ -22170,7 +22175,12 @@ static int deprecated = 0; *buf = 0; - + + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!data) { ast_log(LOG_WARNING, "This function requires a parameter name.\n"); return -1; Index: funcs/func_blacklist.c =================================================================== --- funcs/func_blacklist.c (revision 410669) +++ funcs/func_blacklist.c (working copy) @@ -61,6 +61,11 @@ char blacklist[1]; int bl = 0; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) { if (!ast_db_get("blacklist", ast_channel_caller(chan)->id.number.str, blacklist, sizeof (blacklist))) bl = 1; Index: funcs/func_callcompletion.c =================================================================== --- funcs/func_callcompletion.c (revision 410669) +++ funcs/func_callcompletion.c (working copy) @@ -74,6 +74,11 @@ struct ast_cc_config_params *cc_params; int res; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", name); + return -1; + } + ast_channel_lock(chan); if (!(cc_params = ast_channel_get_cc_config_params(chan))) { ast_channel_unlock(chan); @@ -91,6 +96,11 @@ struct ast_cc_config_params *cc_params; int res; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); if (!(cc_params = ast_channel_get_cc_config_params(chan))) { ast_channel_unlock(chan); Index: funcs/func_callerid.c =================================================================== --- funcs/func_callerid.c (revision 410669) +++ funcs/func_callerid.c (working copy) @@ -900,6 +900,11 @@ */ static int callerpres_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!callerpres_deprecate_notify) { callerpres_deprecate_notify = 1; ast_log(LOG_WARNING, "CALLERPRES is deprecated." @@ -926,6 +931,11 @@ { int pres; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!callerpres_deprecate_notify) { callerpres_deprecate_notify = 1; ast_log(LOG_WARNING, "CALLERPRES is deprecated." Index: funcs/func_channel.c =================================================================== --- funcs/func_channel.c (revision 410669) +++ funcs/func_channel.c (working copy) @@ -405,6 +405,11 @@ int ret = 0; struct ast_format_cap *tmpcap; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + if (!strcasecmp(data, "audionativeformat")) { char tmp[512]; @@ -703,6 +708,11 @@ .value = value, }; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + res = func_channel_write_real(chan, function, data, value); ast_channel_setoption(chan, AST_OPTION_CHANNEL_WRITE, &write_info, sizeof(write_info), 0); @@ -776,8 +786,15 @@ static int func_mchan_read(struct ast_channel *chan, const char *function, char *data, struct ast_str **buf, ssize_t len) { - struct ast_channel *mchan = ast_channel_get_by_name(ast_channel_linkedid(chan)); + struct ast_channel *mchan; char *template = ast_alloca(4 + strlen(data)); + + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + + mchan = ast_channel_get_by_name(ast_channel_linkedid(chan)); sprintf(template, "${%s}", data); /* SAFE */ ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template); if (mchan) { @@ -789,7 +806,14 @@ static int func_mchan_write(struct ast_channel *chan, const char *function, char *data, const char *value) { - struct ast_channel *mchan = ast_channel_get_by_name(ast_channel_linkedid(chan)); + struct ast_channel *mchan; + + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + + mchan = ast_channel_get_by_name(ast_channel_linkedid(chan)); pbx_builtin_setvar_helper(mchan ? mchan : chan, data, value); if (mchan) { ast_channel_unref(mchan); Index: funcs/func_dialplan.c =================================================================== --- funcs/func_dialplan.c (revision 410669) +++ funcs/func_dialplan.c (working copy) @@ -97,12 +97,14 @@ if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) { int res; res = ast_exists_extension(chan, args.context, args.exten, priority_num, + !chan ? NULL : S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)); if (res) strcpy(buf, "1"); } else { int res; res = ast_findlabel_extension(chan, args.context, args.exten, args.priority, + !chan ? NULL : S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)); if (res > 0) strcpy(buf, "1"); @@ -110,6 +112,7 @@ } else if (!ast_strlen_zero(args.exten)) { int res; res = ast_exists_extension(chan, args.context, args.exten, 1, + !chan ? NULL : S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)); if (res) strcpy(buf, "1"); @@ -133,6 +136,11 @@ AST_APP_ARG(priority); ); + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + AST_STANDARD_APP_ARGS(args, parse); if (ast_strlen_zero(args.context)) { Index: funcs/func_frame_trace.c =================================================================== --- funcs/func_frame_trace.c (revision 410669) +++ funcs/func_frame_trace.c (working copy) @@ -157,6 +157,11 @@ }; int i = 0; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!(framedata = ast_calloc(1, sizeof(*framedata)))) { return 0; } Index: funcs/func_global.c =================================================================== --- funcs/func_global.c (revision 410669) +++ funcs/func_global.c (working copy) @@ -155,6 +155,9 @@ return -1; } chan = c_ref; + } else if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; } ast_channel_lock(chan); @@ -213,6 +216,9 @@ return -1; } chan = c_ref; + } else if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; } ast_channel_lock(chan); Index: funcs/func_groupcount.c =================================================================== --- funcs/func_groupcount.c (revision 410669) +++ funcs/func_groupcount.c (working copy) @@ -104,6 +104,11 @@ int count = -1; char group[80] = "", category[80] = ""; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)); @@ -174,7 +179,12 @@ { int ret = -1; struct ast_group_info *gi = NULL; - + + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_app_group_list_rdlock(); for (gi = ast_app_group_list_head(); gi; gi = AST_LIST_NEXT(gi, group_list)) { @@ -201,6 +211,11 @@ { char grpcat[256]; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!value) { return -1; } Index: funcs/func_jitterbuffer.c =================================================================== --- funcs/func_jitterbuffer.c (revision 410669) +++ funcs/func_jitterbuffer.c (working copy) @@ -325,6 +325,11 @@ }; int i = 0; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!(framedata = ast_calloc(1, sizeof(*framedata)))) { return 0; } Index: funcs/func_math.c =================================================================== --- funcs/func_math.c (revision 410669) +++ funcs/func_math.c (working copy) @@ -392,6 +392,11 @@ return -1; } + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); if (!(var = pbx_builtin_getvar_helper(chan, data))) { Index: funcs/func_odbc.c =================================================================== --- funcs/func_odbc.c (revision 410669) +++ funcs/func_odbc.c (working copy) @@ -801,6 +801,11 @@ struct odbc_datastore *resultset; struct odbc_datastore_row *row; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); store = ast_channel_datastore_find(chan, &odbc_info, data); if (!store) { Index: funcs/func_pitchshift.c =================================================================== --- funcs/func_pitchshift.c (revision 410669) +++ funcs/func_pitchshift.c (working copy) @@ -200,6 +200,11 @@ int new = 0; float amount = 0; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); if (!(datastore = ast_channel_datastore_find(chan, &pitchshift_datastore, NULL))) { ast_channel_unlock(chan); Index: funcs/func_speex.c =================================================================== --- funcs/func_speex.c (revision 410669) +++ funcs/func_speex.c (working copy) @@ -202,6 +202,11 @@ struct speex_direction_info **sdi = NULL; int is_new = 0; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (strcasecmp(data, "rx") && strcasecmp(data, "tx")) { ast_log(LOG_ERROR, "Invalid argument provided to the %s function\n", cmd); return -1; Index: funcs/func_strings.c =================================================================== --- funcs/func_strings.c (revision 410669) +++ funcs/func_strings.c (working copy) @@ -1097,6 +1097,11 @@ struct ast_var_t *newvar; struct ast_str *prefix = ast_str_alloca(80); + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_str_set(&prefix, -1, HASH_PREFIX, data); memset(buf, 0, len); @@ -1119,6 +1124,11 @@ struct ast_str *prefix = ast_str_alloca(80); char *tmp; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_str_set(&prefix, -1, HASH_PREFIX, data); AST_LIST_TRAVERSE(ast_channel_varshead(chan), newvar, entries) { @@ -1188,6 +1198,11 @@ AST_APP_ARG(col)[100]; ); + if (!chan) { + ast_log(LOG_WARNING, "No channel and only 1 parameter was provided to %s function.\n", cmd); + return -1; + } + /* Get column names, in no particular order */ hashkeys_read(chan, "HASHKEYS", arg.hashname, colnames, sizeof(colnames)); pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames); Index: funcs/func_volume.c =================================================================== --- funcs/func_volume.c (revision 410669) +++ funcs/func_volume.c (working copy) @@ -162,6 +162,11 @@ AST_APP_ARG(options); ); + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + AST_STANDARD_APP_ARGS(args, data); ast_channel_lock(chan); Index: main/features.c =================================================================== --- main/features.c (revision 410669) +++ main/features.c (working copy) @@ -8913,6 +8913,11 @@ { int res = 0; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!strcasecmp(data, "parkingtime")) { snprintf(buf, len, "%u", get_parkingtime(chan, NULL) / 1000); } else { @@ -8929,6 +8934,11 @@ int res = 0; struct feature_ds *feature_ds; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); if (!(feature_ds = get_feature_ds(chan))) { @@ -8961,6 +8971,11 @@ { int res; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_rdlock_call_features(); if ((res = builtin_feature_get_exten(chan, data, buf, len))) { @@ -8978,6 +8993,11 @@ struct feature_ds *feature_ds; struct feature_exten *fe; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (!ast_find_call_feature(data)) { ast_log(LOG_WARNING, "Invalid argument '%s' to FEATUREMAP()\n", data); return -1; Index: main/message.c =================================================================== --- main/message.c (revision 410669) +++ main/message.c (working copy) @@ -867,6 +867,11 @@ struct ast_datastore *ds; struct ast_msg *msg; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + ast_channel_lock(chan); if (!(ds = ast_channel_datastore_find(chan, &msg_datastore, NULL))) { @@ -903,6 +908,11 @@ struct ast_datastore *ds; struct ast_msg *msg; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + ast_channel_lock(chan); if (!(ds = msg_datastore_find_or_create(chan))) { @@ -959,6 +969,11 @@ struct ast_msg *msg; const char *val; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + ast_channel_lock(chan); if (!(ds = ast_channel_datastore_find(chan, &msg_datastore, NULL))) { @@ -989,6 +1004,11 @@ struct ast_datastore *ds; struct ast_msg *msg; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", function); + return -1; + } + ast_channel_lock(chan); if (!(ds = msg_datastore_find_or_create(chan))) { Index: res/res_calendar.c =================================================================== --- res/res_calendar.c (revision 410669) +++ res/res_calendar.c (working copy) @@ -1673,6 +1673,11 @@ struct ast_datastore *datastore; struct ast_calendar_event *event; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "%s requires an argument\n", cmd); return -1; Index: res/res_jabber.c =================================================================== --- res/res_jabber.c (revision 410669) +++ res/res_jabber.c (working copy) @@ -837,7 +837,7 @@ start = ast_tvnow(); - if (ast_autoservice_start(chan) < 0) { + if (chan && ast_autoservice_start(chan) < 0) { ast_log(LOG_WARNING, "Cannot start autoservice for channel %s\n", ast_channel_name(chan)); ASTOBJ_UNREF(client, ast_aji_client_destroy); return -1; @@ -909,7 +909,7 @@ } ASTOBJ_UNREF(client, ast_aji_client_destroy); - if (ast_autoservice_stop(chan) < 0) { + if (chan && ast_autoservice_stop(chan) < 0) { ast_log(LOG_WARNING, "Cannot stop autoservice for channel %s\n", ast_channel_name(chan)); } Index: res/res_mutestream.c =================================================================== --- res/res_mutestream.c (revision 410669) +++ res/res_mutestream.c (working copy) @@ -235,6 +235,11 @@ int is_new = 0; int turnon; + if (!chan) { + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); + return -1; + } + ast_channel_lock(chan); if (!(datastore = ast_channel_datastore_find(chan, &mute_datastore, NULL))) { if (!(datastore = initialize_mutehook(chan))) { Index: res/res_xmpp.c =================================================================== --- res/res_xmpp.c (revision 410669) +++ res/res_xmpp.c (working copy) @@ -1923,7 +1923,7 @@ start = ast_tvnow(); - if (ast_autoservice_start(chan) < 0) { + if (chan && ast_autoservice_start(chan) < 0) { ast_log(LOG_WARNING, "Cannot start autoservice for channel %s\n", ast_channel_name(chan)); return -1; } @@ -1995,7 +1995,7 @@ diff = ast_tvdiff_ms(ast_tvnow(), start); } - if (ast_autoservice_stop(chan) < 0) { + if (chan && ast_autoservice_stop(chan) < 0) { ast_log(LOG_WARNING, "Cannot stop autoservice for channel %s\n", ast_channel_name(chan)); }