diff --git a/apps/app_jack.c b/apps/app_jack.c
index d1bdfa38f052f4143016332054e114aacdfe201b..f32c59ff0b6fa295e9af8eecadf4c7f86a6e25a8 100644
--- a/apps/app_jack.c
+++ b/apps/app_jack.c
@@ -951,6 +951,11 @@ static int jack_hook_write(struct ast_channel *chan, const char *cmd, char *data
 {
 	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"))
diff --git a/apps/app_speech_utils.c b/apps/app_speech_utils.c
index 81afa88ed0fa313907222c8725fc3477a2ace77c..e9ca63ea9177a7e6995f7d454fda01c6b5555305 100644
--- a/apps/app_speech_utils.c
+++ b/apps/app_speech_utils.c
@@ -285,7 +285,11 @@ static struct ast_speech *find_speech(struct ast_channel *chan)
 {
 	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;
diff --git a/apps/app_stack.c b/apps/app_stack.c
index db335c5070101d265502d6633fc9533a73ec6e7e..72caed8cbd8169e6c70776129e0685d3255e7248 100644
--- a/apps/app_stack.c
+++ b/apps/app_stack.c
@@ -708,6 +708,11 @@ static int local_read(struct ast_channel *chan, const char *cmd, char *data, cha
 	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);
@@ -742,6 +747,11 @@ static int local_write(struct ast_channel *chan, const char *cmd, char *var, con
 	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);
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index f86e4c1f9cf48b5c04c27c60233262f851f9246e..7db2a2564fe9f87c30c5cb3217d14596c792c017 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -12092,7 +12092,9 @@ static int acf_vm_info(struct ast_channel *chan, const char *cmd, char *args, ch
 		} 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) : ast_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)) {
diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c
index 0e81e7e8e85d71e61df8ca9c988af64aa7d88f35..ec841c92c229bece4b5715d0e5faaff4c7c79726 100644
--- a/apps/confbridge/conf_config_parser.c
+++ b/apps/confbridge/conf_config_parser.c
@@ -952,6 +952,11 @@ int func_confbridge_helper(struct ast_channel *chan, const char *cmd, char *data
 		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;
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 185abfc1cff9712d779e60654f9925677cda0274..a83152b0e87851e90e8751a998f4146d68ebafec 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -9872,10 +9872,16 @@ static int socket_process_meta(int packet_len, struct ast_iax2_meta_hdr *meta, s
 
 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;
@@ -9895,10 +9901,16 @@ static int acf_iaxvar_read(struct ast_channel *chan, const char *cmd, char *data
 
 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) {
@@ -14189,8 +14201,9 @@ static int function_iaxpeer(struct ast_channel *chan, const char *cmd, char *dat
 	/* 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, !ast_sockaddr_isnull(&iaxs[callno]->addr) ? ast_sockaddr_stringify_addr(&iaxs[callno]->addr) : "", len);
 		return 0;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 231f376a8d163b574bdf6472f6decebdd7ec11cd..3d52ce4b83230f9bf83514770c39417da1683932 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -22232,7 +22232,12 @@ static int func_header_read(struct ast_channel *chan, const char *function, char
 	);
 	int i, number, start = 0;
 
- 	if (ast_strlen_zero(data)) {
+	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;
 	}
@@ -22418,7 +22423,12 @@ static int function_sipchaninfo_read(struct ast_channel *chan, const char *cmd,
 
 	*buf = 0;
 
- 	if (!data) {
+	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;
 	}
diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c
index 817af002d99e4020d159d3c12255c40019fbe800..86148259aa1d1e3d485620171a68c94bcd600f0e 100644
--- a/channels/pjsip/dialplan_functions.c
+++ b/channels/pjsip/dialplan_functions.c
@@ -682,7 +682,7 @@ static int read_pjsip(void *data)
 int pjsip_acf_channel_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
 	struct pjsip_func_args func_args = { 0, };
-	struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
+	struct ast_sip_channel_pvt *channel;
 	char *parse = ast_strdupa(data);
 
 	AST_DECLARE_APP_ARGS(args,
@@ -691,6 +691,12 @@ int pjsip_acf_channel_read(struct ast_channel *chan, const char *cmd, char *data
 		AST_APP_ARG(field);
 	);
 
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+	channel = ast_channel_tech_pvt(chan);
+
 	/* Check for zero arguments */
 	if (ast_strlen_zero(parse)) {
 		ast_log(LOG_ERROR, "Cannot call %s without arguments\n", cmd);
@@ -863,7 +869,14 @@ static int media_offer_write_av(void *obj)
 
 int pjsip_acf_media_offer_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
-	struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
+	struct ast_sip_channel_pvt *channel;
+
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
+	channel = ast_channel_tech_pvt(chan);
 
 	if (!strcmp(data, "audio")) {
 		return media_offer_read_av(channel->session, buf, len, AST_FORMAT_TYPE_AUDIO);
@@ -876,13 +889,19 @@ int pjsip_acf_media_offer_read(struct ast_channel *chan, const char *cmd, char *
 
 int pjsip_acf_media_offer_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
-	struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
-
+	struct ast_sip_channel_pvt *channel;
 	struct media_offer_data mdata = {
-		.session = channel->session,
 		.value = value
 	};
 
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
+	channel = ast_channel_tech_pvt(chan);
+	mdata.session = channel->session;
+
 	if (!strcmp(data, "audio")) {
 		mdata.media_type = AST_FORMAT_TYPE_AUDIO;
 	} else if (!strcmp(data, "video")) {
diff --git a/funcs/func_blacklist.c b/funcs/func_blacklist.c
index 928d5d728a35e020917c12d0767aa17232f7347a..bb045059b2acf9e1ed42698fc855af33f5e571a1 100644
--- a/funcs/func_blacklist.c
+++ b/funcs/func_blacklist.c
@@ -61,6 +61,11 @@ static int blacklist_read(struct ast_channel *chan, const char *cmd, char *data,
 	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;
diff --git a/funcs/func_callcompletion.c b/funcs/func_callcompletion.c
index cee06faa47ad50edad2a1a85605ff3a4d55de757..cb1cd59b3f1f9d837c12cb4afb7b5cba983fd564 100644
--- a/funcs/func_callcompletion.c
+++ b/funcs/func_callcompletion.c
@@ -74,6 +74,11 @@ static int acf_cc_read(struct ast_channel *chan, const char *name, char *data,
 	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 @@ static int acf_cc_write(struct ast_channel *chan, const char *cmd, char *data,
 	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);
diff --git a/funcs/func_callerid.c b/funcs/func_callerid.c
index b4649c17765327464e84c397a9419f5aadf39c3d..4f6a6779b47c58529cc3e3948c3d297129e77132 100644
--- a/funcs/func_callerid.c
+++ b/funcs/func_callerid.c
@@ -900,6 +900,11 @@ static int callerpres_deprecate_notify;
  */
 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 @@ static int callerpres_write(struct ast_channel *chan, const char *cmd, char *dat
 {
 	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."
diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c
index 0116eee7fa5644cf03f429d6a07f67e46124598d..44ecf4d6b4106a2d553d6c9f2d15ce3725d958a7 100644
--- a/funcs/func_cdr.c
+++ b/funcs/func_cdr.c
@@ -441,6 +441,11 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
 		ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
 	struct cdr_func_data output = { 0, };
 
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
 	if (!payload) {
 		return -1;
 	}
@@ -489,6 +494,11 @@ static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
 	RAII_VAR(struct stasis_message_router *, router,
 		     ast_cdr_message_router(), ao2_cleanup);
 
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
 	if (!router) {
 		ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
 			ast_channel_name(chan));
@@ -522,6 +532,11 @@ static int cdr_prop_write(struct ast_channel *chan, const char *cmd, char *parse
 		ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
 	RAII_VAR(struct stasis_message_router *, router, ast_cdr_message_router(), ao2_cleanup);
 
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
 	if (!router) {
 		ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
 			ast_channel_name(chan));
diff --git a/funcs/func_channel.c b/funcs/func_channel.c
index af9a6a9843b4c0ce5448a23171d1e4402fc1f0e1..cca15c3080c28265e3248ba1e263c77b787e1288 100644
--- a/funcs/func_channel.c
+++ b/funcs/func_channel.c
@@ -421,6 +421,11 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
 	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];
 
@@ -733,6 +738,11 @@ static int func_channel_write(struct ast_channel *chan, const char *function, ch
 		.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);
 
@@ -806,8 +816,15 @@ static struct ast_custom_function channels_function = {
 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) {
@@ -819,7 +836,14 @@ static int func_mchan_read(struct ast_channel *chan, const char *function,
 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);
diff --git a/funcs/func_dialplan.c b/funcs/func_dialplan.c
index d06ddba9a671a1bf0555318601313cf692a333bf..02b4c7a9e48afff56e20dc4a26b47253cc6b34f5 100644
--- a/funcs/func_dialplan.c
+++ b/funcs/func_dialplan.c
@@ -96,20 +96,23 @@ static int isexten_function_read(struct ast_channel *chan, const char *cmd, char
 		int priority_num;
 		if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
 			int res;
-			res = ast_exists_extension(chan, args.context, args.exten, priority_num, 
+			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");
 		}
 	} else if (!ast_strlen_zero(args.exten)) {
 		int res;
-		res = ast_exists_extension(chan, args.context, args.exten, 1, 
+		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 @@ static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *par
 		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)) {
diff --git a/funcs/func_frame_trace.c b/funcs/func_frame_trace.c
index bdbc596e64de4f4bb3e5f677217fe0a2a63103dd..6452d0bcb56143290caf9f9a031f9463ad9fc96a 100644
--- a/funcs/func_frame_trace.c
+++ b/funcs/func_frame_trace.c
@@ -157,6 +157,11 @@ static int frame_trace_helper(struct ast_channel *chan, const char *cmd, char *d
 	};
 	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;
 	}
diff --git a/funcs/func_global.c b/funcs/func_global.c
index 374720205f7bc00779f6f1870914f2b7f40f33b2..a2329c46e91a0ec1d42d3377154fb1fc5809964a 100644
--- a/funcs/func_global.c
+++ b/funcs/func_global.c
@@ -173,6 +173,9 @@ static int shared_read(struct ast_channel *chan, const char *cmd, char *data, ch
 			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);
@@ -233,6 +236,9 @@ static int shared_write(struct ast_channel *chan, const char *cmd, char *data, c
 			return -1;
 		}
 		chan = c_ref;
+	} else if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
 	}
 
 	len = 9 + strlen(args.var); /* SHARED() + var */
diff --git a/funcs/func_groupcount.c b/funcs/func_groupcount.c
index 95ee0cde6181b8e6870a23502eb52dcd6faa6962..4ea6816918d98f36094f02e0ccab53e861b9daa5 100644
--- a/funcs/func_groupcount.c
+++ b/funcs/func_groupcount.c
@@ -104,6 +104,11 @@ static int group_count_function_read(struct ast_channel *chan, const char *cmd,
 	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,9 +179,14 @@ static int group_function_read(struct ast_channel *chan, const char *cmd,
 {
 	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)) {
 		if (gi->chan != chan)
 			continue;
@@ -201,6 +211,11 @@ static int group_function_write(struct ast_channel *chan, const char *cmd,
 {
 	char grpcat[256];
 
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
 	if (!value) {
 		return -1;
 	}
diff --git a/funcs/func_jitterbuffer.c b/funcs/func_jitterbuffer.c
index a00361043c2ac6210f0a8b9975189d582e8c36bc..31ab86ce31aac0378ed860bda28c510086518d6a 100644
--- a/funcs/func_jitterbuffer.c
+++ b/funcs/func_jitterbuffer.c
@@ -85,6 +85,11 @@ static int jb_helper(struct ast_channel *chan, const char *cmd, char *data, cons
 {
 	struct ast_jb_conf jb_conf;
 
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
 	/* Initialize and set jb_conf */
 	ast_jb_conf_default(&jb_conf);
 
diff --git a/funcs/func_math.c b/funcs/func_math.c
index 36f3fc48a6848f32253900bee8e7d4b88e6c4175..2bc68c579a8ea9aab86b2d88f8b151349fccc41a 100644
--- a/funcs/func_math.c
+++ b/funcs/func_math.c
@@ -392,6 +392,11 @@ static int crement_function_read(struct ast_channel *chan, const char *cmd,
 		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))) {
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index 4469ca7a272b0f04d3e89c29778aea4f22dec5ea..5e7655f908c9008549a3941336f6f4459ac7a5e6 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -801,6 +801,11 @@ static int acf_fetch(struct ast_channel *chan, const char *cmd, char *data, char
 	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) {
diff --git a/funcs/func_pitchshift.c b/funcs/func_pitchshift.c
index ca441f985079d9385f6cb655012c9e7c02a9aab8..e5091d95dd8be46ca7131ac930cc697a724f539d 100644
--- a/funcs/func_pitchshift.c
+++ b/funcs/func_pitchshift.c
@@ -200,6 +200,11 @@ static int pitchshift_helper(struct ast_channel *chan, const char *cmd, char *da
 	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);
diff --git a/funcs/func_speex.c b/funcs/func_speex.c
index 7467c23bbd89fbdca561778ab668440856235901..4e3c13b87e138a6a18a61896523ac19c7c87f3da 100644
--- a/funcs/func_speex.c
+++ b/funcs/func_speex.c
@@ -202,6 +202,11 @@ static int speex_write(struct ast_channel *chan, const char *cmd, char *data, co
 	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;
diff --git a/funcs/func_strings.c b/funcs/func_strings.c
index 3dd0168f1ab9d765944ec06ca5069711e6305ad1..ac889ec04855a08520b5e8e7b2a6fdc643631357 100644
--- a/funcs/func_strings.c
+++ b/funcs/func_strings.c
@@ -1097,6 +1097,11 @@ static int hashkeys_read(struct ast_channel *chan, const char *cmd, char *data,
 	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 @@ static int hashkeys_read2(struct ast_channel *chan, const char *cmd, char *data,
 	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 @@ static int hash_read(struct ast_channel *chan, const char *cmd, char *data, char
 			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);
diff --git a/funcs/func_volume.c b/funcs/func_volume.c
index 953a37dcdd97423018133f0ec0413f0babcac454..9fd02008fe8e1458d01cdbf967f33806834a1058 100644
--- a/funcs/func_volume.c
+++ b/funcs/func_volume.c
@@ -156,12 +156,17 @@ static int volume_write(struct ast_channel *chan, const char *cmd, char *data, c
 	int is_new = 0;
 
 	/* Separate options from argument */
-	
+
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(direction);
 		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);
diff --git a/main/features_config.c b/main/features_config.c
index 3d2ded576b9d88e266d707407bbe139ec7b809af..d58886eec78c851804c9db6d925abbc21059cdc6 100644
--- a/main/features_config.c
+++ b/main/features_config.c
@@ -1535,7 +1535,7 @@ static int features_pre_apply_config(void)
 	return err;
 }
 
-static int feature_read(struct ast_channel *chan, const char *cmd, char *data,
+static int internal_feature_read(struct ast_channel *chan, const char *cmd, char *data,
 	       char *buf, size_t len)
 {
 	int res;
@@ -1566,7 +1566,7 @@ static int feature_read(struct ast_channel *chan, const char *cmd, char *data,
 	return res;
 }
 
-static int feature_write(struct ast_channel *chan, const char *cmd, char *data,
+static int internal_feature_write(struct ast_channel *chan, const char *cmd, char *data,
 		const char *value)
 {
 	int res;
@@ -1596,7 +1596,7 @@ static int feature_write(struct ast_channel *chan, const char *cmd, char *data,
 	return res;
 }
 
-static int featuremap_read(struct ast_channel *chan, const char *cmd, char *data,
+static int internal_featuremap_read(struct ast_channel *chan, const char *cmd, char *data,
 	       char *buf, size_t len)
 {
 	int res;
@@ -1611,7 +1611,7 @@ static int featuremap_read(struct ast_channel *chan, const char *cmd, char *data
 	return res;
 }
 
-static int featuremap_write(struct ast_channel *chan, const char *cmd, char *data,
+static int internal_featuremap_write(struct ast_channel *chan, const char *cmd, char *data,
 		const char *value)
 {
 	int res;
@@ -1631,6 +1631,50 @@ static int featuremap_write(struct ast_channel *chan, const char *cmd, char *dat
 	return 0;
 }
 
+static int feature_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;
+	}
+
+	return internal_feature_read(chan, cmd, data, buf, len);
+}
+
+static int feature_write(struct ast_channel *chan, const char *cmd, char *data,
+		const char *value)
+{
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
+	return internal_feature_write(chan, cmd, data, value);
+}
+
+static int featuremap_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;
+	}
+
+	return internal_featuremap_read(chan, cmd, data, buf, len);
+}
+
+static int featuremap_write(struct ast_channel *chan, const char *cmd, char *data,
+		const char *value)
+{
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
+	return internal_featuremap_write(chan, cmd, data, value);
+}
+
 static struct ast_custom_function feature_function = {
 	.name = "FEATURE",
 	.read = feature_read,
diff --git a/main/message.c b/main/message.c
index 70bda4150a1250d5d66ce78daec5558c99c7c657..bd706e36382861a42c0dc8369f0036b6e2f777af 100644
--- a/main/message.c
+++ b/main/message.c
@@ -871,6 +871,11 @@ static int msg_func_read(struct ast_channel *chan, const char *function,
 	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))) {
@@ -907,6 +912,11 @@ static int msg_func_write(struct ast_channel *chan, const char *function,
 	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))) {
@@ -963,6 +973,11 @@ static int msg_data_func_read(struct ast_channel *chan, const char *function,
 	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))) {
@@ -993,6 +1008,11 @@ static int msg_data_func_write(struct ast_channel *chan, const char *function,
 	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))) {
diff --git a/res/res_calendar.c b/res/res_calendar.c
index f279e73a0d0a25c0171e8e8578d213348809602f..e6c93fdc7606a536875255ba04fffd931b365fef 100644
--- a/res/res_calendar.c
+++ b/res/res_calendar.c
@@ -1685,6 +1685,11 @@ static int calendar_event_read(struct ast_channel *chan, const char *cmd, char *
 	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;
diff --git a/res/res_jabber.c b/res/res_jabber.c
index 41dd70c02844054e92f61a94f89ec8d650e43530..ede498124ce0da432634acd3e0f449857112639a 100644
--- a/res/res_jabber.c
+++ b/res/res_jabber.c
@@ -845,7 +845,7 @@ static int acf_jabberreceive_read(struct ast_channel *chan, const char *name, ch
 
 	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;
@@ -917,7 +917,7 @@ static int acf_jabberreceive_read(struct ast_channel *chan, const char *name, ch
 	}
 
 	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));
 	}
 
diff --git a/res/res_mutestream.c b/res/res_mutestream.c
index b907fbe3a8d101c8083b0f551c718235ab69af80..479b3d7ca376917aff1ad98e335280d52b05360f 100644
--- a/res/res_mutestream.c
+++ b/res/res_mutestream.c
@@ -155,6 +155,11 @@ static int mute_channel(struct ast_channel *chan, const char *direction, int mut
 /*! \brief Mute dialplan function */
 static int func_mute_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
+	if (!chan) {
+		ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
+		return -1;
+	}
+
 	return mute_channel(chan, data, ast_true(value));
 }
 
diff --git a/res/res_pjsip_header_funcs.c b/res/res_pjsip_header_funcs.c
index 5d09d10c65a7199026ea007a60a15e901d76edd8..b5383fb324c938e0501ddc99db2fdc359dcc31a0 100644
--- a/res/res_pjsip_header_funcs.c
+++ b/res/res_pjsip_header_funcs.c
@@ -444,7 +444,7 @@ static int remove_header(void *obj)
 static int func_read_header(struct ast_channel *chan, const char *function, char *data,
 							char *buf, size_t len)
 {
-	struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
+	struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL;
 	struct header_data header_data;
 	int number;
 	AST_DECLARE_APP_ARGS(args,
@@ -503,7 +503,7 @@ static int func_read_header(struct ast_channel *chan, const char *function, char
 static int func_write_header(struct ast_channel *chan, const char *cmd, char *data,
 							 const char *value)
 {
-	struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
+	struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL;
 	struct header_data header_data;
 	int header_number;
 	AST_DECLARE_APP_ARGS(args,
diff --git a/res/res_xmpp.c b/res/res_xmpp.c
index c067fdec43e193bba2c89a76ed21096276836808..fcdd2c4a8af41a81edaf11513f2e7d7b5b931f5f 100644
--- a/res/res_xmpp.c
+++ b/res/res_xmpp.c
@@ -2045,7 +2045,7 @@ static int acf_jabberreceive_read(struct ast_channel *chan, const char *name, ch
 
 	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;
 	}
@@ -2117,7 +2117,7 @@ static int acf_jabberreceive_read(struct ast_channel *chan, const char *name, ch
 		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));
 	}