]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix some bugs in process_message(). The manager session lock needs to be held
authorRussell Bryant <russell@russellbryant.com>
Tue, 23 Jan 2007 22:04:01 +0000 (22:04 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 23 Jan 2007 22:04:01 +0000 (22:04 +0000)
when sending some sort of response, or calling one of the manager action
callbacks.  This resolves an issue where people using the GUI would get random
crashes when they start clicking around a lot.
(issue #8711, reported and debugged by zandbelt)

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

main/manager.c

index 0b5ff19392ff168f7dea8f5f4b6d8e65c3218d1e..b92226539bb1b60369d6ac6852377b02e108781c 100644 (file)
@@ -1966,7 +1966,9 @@ static int process_message(struct mansession *s, const struct message *m)
        ast_log( LOG_DEBUG, "Manager received command '%s'\n", action );
 
        if (ast_strlen_zero(action)) {
+               ast_mutex_lock(&s->__lock);
                astman_send_error(s, m, "Missing action in request");
+               ast_mutex_unlock(&s->__lock);
                return 0;
        }
        if (!ast_strlen_zero(id)) {
@@ -1987,13 +1989,17 @@ static int process_message(struct mansession *s, const struct message *m)
                                ast_mutex_unlock(&s->__lock);
                                return 0;
                        } else {
+                               ast_mutex_lock(&s->__lock);
                                astman_send_error(s, m, "Must specify AuthType");
+                               ast_mutex_unlock(&s->__lock);
                                return 0;
                        }
                } else if (!strcasecmp(action, "Login")) {
                        if (authenticate(s, m)) {
                                sleep(1);
+                               ast_mutex_lock(&s->__lock);
                                astman_send_error(s, m, "Authentication failed");
+                               ast_mutex_unlock(&s->__lock);
                                return -1;
                        } else {
                                s->authenticated = 1;
@@ -2003,10 +2009,14 @@ static int process_message(struct mansession *s, const struct message *m)
                                        }
                                }
                                ast_log(LOG_EVENT, "%sManager '%s' logged on from %s\n", (s->sessiontimeout ? "HTTP " : ""), s->username, ast_inet_ntoa(s->sin.sin_addr));
+                               ast_mutex_lock(&s->__lock);
                                astman_send_ack(s, m, "Authentication accepted");
+                               ast_mutex_unlock(&s->__lock);
                        }
                } else if (!strcasecmp(action, "Logoff")) {
+                       ast_mutex_lock(&s->__lock);
                        astman_send_ack(s, m, "See ya");
+                       ast_mutex_unlock(&s->__lock);
                        return -1;
                } else
                        astman_send_error(s, m, "Authentication Required");
@@ -2015,11 +2025,13 @@ static int process_message(struct mansession *s, const struct message *m)
                for (tmp = first_action; tmp; tmp = tmp->next) {                
                        if (strcasecmp(action, tmp->action))
                                continue;
+                       ast_mutex_lock(&s->__lock);
                        if ((s->writeperm & tmp->authority) == tmp->authority) {
                                if (tmp->func(s, m))
                                        ret = -1;
                        } else
                                astman_send_error(s, m, "Permission denied");
+                       ast_mutex_unlock(&s->__lock);
                        break;
                }
                ast_mutex_unlock(&actionlock);