]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Don't keep trying to write to a closed connection
authorTerry Wilson <twilson@digium.com>
Wed, 16 Mar 2011 19:28:41 +0000 (19:28 +0000)
committerTerry Wilson <twilson@digium.com>
Wed, 16 Mar 2011 19:28:41 +0000 (19:28 +0000)
See security advisory AST-2011-003.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@310994 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/manager.c

index 1604770f4fc14118cc899e98f5af1b6549fc0a7d..70b2593c39874b22a06afdee1260af8f66a1f7c7 100644 (file)
@@ -220,6 +220,7 @@ struct mansession {
        struct mansession_session *session;
        FILE *f;
        int fd;
+       int write_error:1;
 };
 
 #define NEW_EVENT(m)   (AST_LIST_NEXT(m->session->last_ev, eq_next))
@@ -944,11 +945,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;
 }
 
 /*!
@@ -3207,7 +3212,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 */