From: Terry Wilson Date: Wed, 16 Mar 2011 19:23:03 +0000 (+0000) Subject: Don't keep trying to write to a closed connection X-Git-Tag: 1.6.2.19-rc1~3^2~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ae012e658f73543328a567f9a2258d364b2f722;p=thirdparty%2Fasterisk.git Don't keep trying to write to a closed connection See security advisory AST-2011-003. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.2@310992 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/manager.c b/main/manager.c index eac123c143..5ab7a37e4c 100644 --- a/main/manager.c +++ b/main/manager.c @@ -228,6 +228,7 @@ struct mansession { struct mansession_session *session; FILE *f; int fd; + int write_error:1; }; static AST_LIST_HEAD_STATIC(sessions, mansession_session); @@ -964,11 +965,15 @@ struct ast_variable *astman_get_variables(const struct message *m) */ static int send_string(struct mansession *s, char *string) { - if (s->f) { - return ast_careful_fwrite(s->f, s->fd, string, strlen(string), s->session->writetimeout); - } else { - return ast_careful_fwrite(s->session->f, s->session->fd, string, strlen(string), s->session->writetimeout); + int res; + + if (s->f && (res = ast_careful_fwrite(s->f, s->fd, string, strlen(string), s->session->writetimeout))) { + s->write_error = 1; + } else if ((res = ast_careful_fwrite(s->session->f, s->session->fd, string, strlen(string), s->session->writetimeout))) { + s->write_error = 1; } + + return res; } /*! @@ -3277,7 +3282,7 @@ static void *session_do(void *data) astman_append(&s, "Asterisk Call Manager/%s\r\n", AMI_VERSION); /* welcome prompt */ for (;;) { - if ((res = do_message(&s)) < 0) + if ((res = do_message(&s)) < 0 || s.write_error) break; } /* session is over, explain why and terminate */