From e040a10d819559c05dcacf437515d7a6aae59f85 Mon Sep 17 00:00:00 2001
From: Russell Bryant <russell@russellbryant.com>
Date: Sat, 21 Jan 2006 20:20:06 +0000
Subject: [PATCH] finish reverting my pass through the tree to remove checks of
 the result of ast_strdupa, this one is revision 8362

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8401 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 app.c      |  9 +++++----
 callerid.c |  6 +++++-
 channel.c  |  7 ++++++-
 pbx.c      | 46 ++++++++++++++++++++++++++++++++++------------
 4 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/app.c b/app.c
index bf7bd345be..fedc95d572 100644
--- a/app.c
+++ b/app.c
@@ -1358,11 +1358,12 @@ static int ivr_dispatch(struct ast_channel *chan, struct ast_ivr_option *option,
 	case AST_ACTION_BACKLIST:
 		res = 0;
 		c = ast_strdupa(option->adata);
-		while ((n = strsep(&c, ";"))) {
-			if ((res = ast_streamfile(chan, n, chan->language)) || (res = ast_waitstream(chan, (option->action == AST_ACTION_BACKLIST) ? AST_DIGIT_ANY : "")))
-				break;
+		if (c) {
+			while((n = strsep(&c, ";")))
+				if ((res = ast_streamfile(chan, n, chan->language)) || (res = ast_waitstream(chan, (option->action == AST_ACTION_BACKLIST) ? AST_DIGIT_ANY : "")))
+					break;
+			ast_stopstream(chan);
 		}
-		ast_stopstream(chan);
 		return res;
 	default:
 		ast_log(LOG_NOTICE, "Unknown dispatch function %d, ignoring!\n", option->action);
diff --git a/callerid.c b/callerid.c
index 92a25e9f26..161f5196d3 100644
--- a/callerid.c
+++ b/callerid.c
@@ -996,8 +996,12 @@ int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int
 {
 	char *tmp;
 	char *l = NULL, *n = NULL;
-	
 	tmp = ast_strdupa(buf);
+	if (!tmp) {
+		name[0] = '\0';
+		num[0] = '\0';
+		return -1;
+	}
 	ast_callerid_parse(tmp, &n, &l);
 	if (n)
 		ast_copy_string(name, n, namelen);
diff --git a/channel.c b/channel.c
index 8f0e5d2be9..f331f6af82 100644
--- a/channel.c
+++ b/channel.c
@@ -3705,7 +3705,12 @@ ast_group_t ast_get_group(char *s)
 	int start=0, finish=0, x;
 	ast_group_t group = 0;
 
-	c = copy = ast_strdupa(s);
+	copy = ast_strdupa(s);
+	if (!copy) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		return 0;
+	}
+	c = copy;
 	
 	while ((piece = strsep(&c, ","))) {
 		if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
diff --git a/pbx.c b/pbx.c
index 79a2f6d3f8..99840addff 100644
--- a/pbx.c
+++ b/pbx.c
@@ -1220,6 +1220,10 @@ char *ast_func_read(struct ast_channel *chan, const char *in, char *workspace, s
 	struct ast_custom_function *acfptr;
 
 	function = ast_strdupa(in);
+	if (!function) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		return ret;
+	}
 	if ((args = strchr(function, '('))) {
 		*args = '\0';
 		args++;
@@ -1251,6 +1255,10 @@ void ast_func_write(struct ast_channel *chan, const char *in, const char *value)
 	struct ast_custom_function *acfptr;
 
 	function = ast_strdupa(in);
+	if (!function) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		return;
+	}
 	if ((args = strchr(function, '('))) {
 		*args = '\0';
 		args++;
@@ -3341,7 +3349,7 @@ static int handle_show_dialplan(int fd, int argc, char *argv[])
 	if (argc == 3) {
 		char *splitter = ast_strdupa(argv[2]);
 		/* is there a '@' character? */
-		if (strchr(argv[2], '@')) {
+		if (splitter && strchr(argv[2], '@')) {
 			/* yes, split into exten & context ... */
 			exten   = strsep(&splitter, "@");
 			context = splitter;
@@ -5138,6 +5146,10 @@ static int pbx_builtin_resetcdr(struct ast_channel *chan, void *data)
 	
 	if (!ast_strlen_zero(data)) {
 		args = ast_strdupa(data);
+		if (!args) {
+			ast_log(LOG_ERROR, "Out of memory!\n");
+			return -1;
+		}
 		ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
 	}
 
@@ -5175,7 +5187,7 @@ static int pbx_builtin_hangup(struct ast_channel *chan, void *data)
  */
 static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data)
 {
-	int res = 0;
+	int res=0;
 	char *s, *ts;
 	struct ast_timing timing;
 
@@ -5184,15 +5196,18 @@ static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data)
 		return -1;
 	}
 
-	ts = s = ast_strdupa(data);
+	if ((s = ast_strdupa(data))) {
+		ts = s;
 
-	/* Separate the Goto path */
-	strsep(&ts,"?");
+		/* Separate the Goto path */
+		strsep(&ts,"?");
 
-	/* struct ast_include include contained garbage here, fixed by zeroing it on get_timerange */
-	if (ast_build_timing(&timing, s) && ast_check_timing(&timing))
-		res = pbx_builtin_goto(chan, (void *)ts);
-	
+		/* struct ast_include include contained garbage here, fixed by zeroing it on get_timerange */
+		if (ast_build_timing(&timing, s) && ast_check_timing(&timing))
+			res = pbx_builtin_goto(chan, (void *)ts);
+	} else {
+		ast_log(LOG_ERROR, "Memory Error!\n");
+	}
 	return res;
 }
 
@@ -5212,11 +5227,17 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
 		return -1;
 	}
 
-	ptr2 = ptr1 = ast_strdupa(data);
+	ptr1 = ast_strdupa(data);
+
+	if (!ptr1) {
+		ast_log(LOG_ERROR, "Out of Memory!\n");
+		return -1;	
+	}
 
+	ptr2 = ptr1;
 	/* Separate the Application data ptr1 is the time spec ptr2 is the app|data */
 	strsep(&ptr2,"?");
-	if (!ast_build_timing(&timing, ptr1)) {
+	if(!ast_build_timing(&timing, ptr1)) {
 		ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", ptr1, usage);
 		res = -1;
 	}
@@ -5983,7 +6004,8 @@ int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
 		ast_log(LOG_WARNING, "Goto requires an argument (optional context|optional extension|priority)\n");
 		return -1;
 	}
-	stringp = s = ast_strdupa(goto_string);
+	s = ast_strdupa(goto_string);
+	stringp=s;
 	context = strsep(&stringp, "|");
 	exten = strsep(&stringp, "|");
 	if (!exten) {
-- 
GitLab