mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 11:42:27 +00:00
Merged revisions 331576 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/10 ................ r331576 | rmudgett | 2011-08-11 16:42:21 -0500 (Thu, 11 Aug 2011) | 16 lines Merged revisions 331575 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r331575 | rmudgett | 2011-08-11 16:39:58 -0500 (Thu, 11 Aug 2011) | 9 lines 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 ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@331577 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -42,29 +42,38 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
static int shell_helper(struct ast_channel *chan, const char *cmd, char *data,
|
static int shell_helper(struct ast_channel *chan, const char *cmd, char *data,
|
||||||
char *buf, size_t len)
|
char *buf, size_t len)
|
||||||
{
|
{
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
if (ast_strlen_zero(data)) {
|
if (ast_strlen_zero(data)) {
|
||||||
ast_log(LOG_WARNING, "Missing Argument! Example: Set(foo=${SHELL(echo \"bar\")})\n");
|
ast_log(LOG_WARNING, "Missing Argument! Example: Set(foo=${SHELL(echo \"bar\")})\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chan)
|
if (chan) {
|
||||||
ast_autoservice_start(chan);
|
ast_autoservice_start(chan);
|
||||||
|
}
|
||||||
|
|
||||||
if (len >= 1) {
|
if (len >= 1) {
|
||||||
FILE *ptr;
|
FILE *ptr;
|
||||||
char plbuff[4096];
|
char plbuff[4096];
|
||||||
|
|
||||||
ptr = popen(data, "r");
|
ptr = popen(data, "r");
|
||||||
|
if (ptr) {
|
||||||
while (fgets(plbuff, sizeof(plbuff), ptr)) {
|
while (fgets(plbuff, sizeof(plbuff), ptr)) {
|
||||||
strncat(buf, plbuff, len - strlen(buf) - 1);
|
strncat(buf, plbuff, len - strlen(buf) - 1);
|
||||||
}
|
}
|
||||||
pclose(ptr);
|
pclose(ptr);
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_WARNING, "Failed to execute shell command '%s'\n", data);
|
||||||
|
res = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chan)
|
if (chan) {
|
||||||
ast_autoservice_stop(chan);
|
ast_autoservice_stop(chan);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** DOCUMENTATION
|
/*** DOCUMENTATION
|
||||||
|
Reference in New Issue
Block a user