Merged revisions 310992 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.6.2

........
  r310992 | twilson | 2011-03-16 14:23:03 -0500 (Wed, 16 Mar 2011) | 4 lines
  
  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.8@310993 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Terry Wilson
2011-03-16 19:26:57 +00:00
parent bec22e5c1f
commit d37bdd02dc

View File

@@ -971,6 +971,7 @@ struct mansession {
struct ast_tcptls_session_instance *tcptls_session;
FILE *f;
int fd;
int write_error:1;
struct manager_custom_hook *hook;
ast_mutex_t lock;
};
@@ -1844,6 +1845,7 @@ int ast_hook_send_action(struct manager_custom_hook *hook, const char *msg)
*/
static int send_string(struct mansession *s, char *string)
{
int res;
/* It's a result from one of the hook's action invocation */
if (s->hook) {
/*
@@ -1852,11 +1854,13 @@ static int send_string(struct mansession *s, char *string)
*/
s->hook->helper(EVENT_FLAG_HOOKRESPONSE, "HookResponse", string);
return 0;
} else 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);
} else 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;
}
/*!
@@ -4673,7 +4677,7 @@ static void *session_do(void *data)
ao2_unlock(session);
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;
}
}