Skip to content
Snippets Groups Projects
Commit 9f7ce9da authored by Mark Michelson's avatar Mark Michelson
Browse files

Fix a file playback crash and explicitly initialize values in func_timeout.c

A crash was brought up on the bugtracker. The first run through valgrind
was full of legitimate complaints of uninitialized values in func_timeout when
setting a response timeout. These were fixed but the crash persisted.

A second run through showed the real problem. The reference counting used
for filestreams was incorrect because there were some missing increments
when a frame was read from a format module.

(closes issue #14118)
Reported by: blitzrage
Patches:
      14118v2.patch uploaded by putnopvut (license 60)
Tested by: blitzrage



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@166267 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 8556f306
No related branches found
No related tags found
No related merge requests found
...@@ -119,11 +119,12 @@ static int timeout_read(struct ast_channel *chan, const char *cmd, char *data, ...@@ -119,11 +119,12 @@ static int timeout_read(struct ast_channel *chan, const char *cmd, char *data,
static int timeout_write(struct ast_channel *chan, const char *cmd, char *data, static int timeout_write(struct ast_channel *chan, const char *cmd, char *data,
const char *value) const char *value)
{ {
double x; double x = 0.0;
long sec; long sec = 0L;
char timestr[64]; char timestr[64];
struct ast_tm myt; struct ast_tm myt;
struct timeval when; struct timeval when = {0,};
int res;
if (!chan) if (!chan)
return -1; return -1;
...@@ -136,9 +137,13 @@ static int timeout_write(struct ast_channel *chan, const char *cmd, char *data, ...@@ -136,9 +137,13 @@ static int timeout_write(struct ast_channel *chan, const char *cmd, char *data,
if (!value) if (!value)
return -1; return -1;
if ((sscanf(value, "%ld%lf", &sec, &x) == 0) || sec < 0) res = sscanf(value, "%ld%lf", &sec, &x);
if (res == 0 || sec < 0) {
when.tv_sec = 0; when.tv_sec = 0;
else { when.tv_usec = 0;
} else if (res == 1) {
when.tv_sec = sec;
} else if (res == 2) {
when.tv_sec = sec; when.tv_sec = sec;
when.tv_usec = x * 1000000; when.tv_usec = x * 1000000;
} }
......
...@@ -714,6 +714,10 @@ static enum fsread_res ast_readaudio_callback(struct ast_filestream *s) ...@@ -714,6 +714,10 @@ static enum fsread_res ast_readaudio_callback(struct ast_filestream *s)
goto return_failure; goto return_failure;
fr = s->fmt->read(s, &whennext); fr = s->fmt->read(s, &whennext);
if (fr) {
ast_set_flag(fr, AST_FRFLAG_FROM_FILESTREAM);
ao2_ref(s, +1);
}
if (!fr /* stream complete */ || ast_write(s->owner, fr) /* error writing */) { if (!fr /* stream complete */ || ast_write(s->owner, fr) /* error writing */) {
if (fr) if (fr)
ast_log(LOG_WARNING, "Failed to write frame\n"); ast_log(LOG_WARNING, "Failed to write frame\n");
...@@ -764,6 +768,10 @@ static enum fsread_res ast_readvideo_callback(struct ast_filestream *s) ...@@ -764,6 +768,10 @@ static enum fsread_res ast_readvideo_callback(struct ast_filestream *s)
while (!whennext) { while (!whennext) {
struct ast_frame *fr = s->fmt->read(s, &whennext); struct ast_frame *fr = s->fmt->read(s, &whennext);
if (fr) {
ast_set_flag(fr, AST_FRFLAG_FROM_FILESTREAM);
ao2_ref(s, +1);
}
if (!fr || ast_write(s->owner, fr)) { /* no stream or error, as above */ if (!fr || ast_write(s->owner, fr)) { /* no stream or error, as above */
if (fr) if (fr)
ast_log(LOG_WARNING, "Failed to write frame\n"); ast_log(LOG_WARNING, "Failed to write frame\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment