[asterisk-commits] branch 1.2 - r7251 /branches/1.2/apps/app_externalivr.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Nov 30 20:34:00 CST 2005


Author: russell
Date: Wed Nov 30 20:33:58 2005
New Revision: 7251

URL: http://svn.digium.com/view/asterisk?rev=7251&view=rev
Log:
use ast_app_separate_args to split arguments (issue #5686)

Modified:
    branches/1.2/apps/app_externalivr.c

Modified: branches/1.2/apps/app_externalivr.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/apps/app_externalivr.c?rev=7251&r1=7250&r2=7251&view=diff
==============================================================================
--- branches/1.2/apps/app_externalivr.c (original)
+++ branches/1.2/apps/app_externalivr.c Wed Nov 30 20:33:58 2005
@@ -43,6 +43,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/app.h"
 
 static const char *tdesc = "External IVR Interface Application";
 
@@ -250,10 +251,9 @@
 	int res = -1;
 	int gen_active = 0;
 	int pid;
-	char *command;
 	char *argv[32];
 	int argc = 1;
-	char *buf;
+	char *buf, *command;
 	FILE *child_commands = NULL;
 	FILE *child_errors = NULL;
 	FILE *child_events = NULL;
@@ -270,11 +270,13 @@
 	}
 
 	buf = ast_strdupa(data);
-	command = strsep(&buf, "|");
-	memset(argv, 0, sizeof(argv) / sizeof(argv[0]));
-	argv[0] = command;
-	while ((argc < 31) && (argv[argc++] = strsep(&buf, "|")));
-	argv[argc] = NULL;
+	if (!buf) {
+		ast_log(LOG_ERROR, "Out of memory!\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
+	argc = ast_app_separate_args(buf, '|', argv, sizeof(argv) / sizeof(argv[0]));
 
 	if (pipe(child_stdin)) {
 		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child input: %s\n", strerror(errno));
@@ -316,8 +318,8 @@
 		dup2(child_stderr[1], STDERR_FILENO);
 		for (i = STDERR_FILENO + 1; i < 1024; i++)
 			close(i);
-		execv(command, argv);
-		fprintf(stderr, "Failed to execute '%s': %s\n", command, strerror(errno));
+		execv(argv[0], argv);
+		fprintf(stderr, "Failed to execute '%s': %s\n", argv[0], strerror(errno));
 		exit(1);
 	} else {
 		/* parent process */



More information about the asterisk-commits mailing list