[asterisk-commits] rmudgett: branch 1.8 r331575 - /branches/1.8/funcs/func_shell.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 11 16:40:02 CDT 2011


Author: rmudgett
Date: Thu Aug 11 16:39:58 2011
New Revision: 331575

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=331575
Log:
Segfault in shell_helper in func_shell.c.

The return value of popen() was not checked for failure to open.

(closes issue ASTERISK-18109)
JIRA SWP-3633
Reported by: Michael Myles
Tested by: rmudgett

Modified:
    branches/1.8/funcs/func_shell.c

Modified: branches/1.8/funcs/func_shell.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_shell.c?view=diff&rev=331575&r1=331574&r2=331575
==============================================================================
--- branches/1.8/funcs/func_shell.c (original)
+++ branches/1.8/funcs/func_shell.c Thu Aug 11 16:39:58 2011
@@ -42,29 +42,38 @@
 static int shell_helper(struct ast_channel *chan, const char *cmd, char *data,
 		                         char *buf, size_t len)
 {
+	int res = 0;
+
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Missing Argument!  Example:  Set(foo=${SHELL(echo \"bar\")})\n");
 		return -1;
 	}
 
-	if (chan)
+	if (chan) {
 		ast_autoservice_start(chan);
+	}
 
 	if (len >= 1) {
 		FILE *ptr;
 		char plbuff[4096];
 
 		ptr = popen(data, "r");
-		while (fgets(plbuff, sizeof(plbuff), ptr)) {
-			strncat(buf, plbuff, len - strlen(buf) - 1);
+		if (ptr) {
+			while (fgets(plbuff, sizeof(plbuff), ptr)) {
+				strncat(buf, plbuff, len - strlen(buf) - 1);
+			}
+			pclose(ptr);
+		} else {
+			ast_log(LOG_WARNING, "Failed to execute shell command '%s'\n", data);
+			res = -1;
 		}
-		pclose(ptr);
 	}
 
-	if (chan)
+	if (chan) {
 		ast_autoservice_stop(chan);
+	}
 
-	return 0;
+	return res;
 }
 
 /*** DOCUMENTATION




More information about the asterisk-commits mailing list