Fix segfault when dialing a typo'd queue
authorMark Michelson <mmichelson@digium.com>
Wed, 11 Mar 2009 14:28:40 +0000 (14:28 +0000)
committerMark Michelson <mmichelson@digium.com>
Wed, 11 Mar 2009 14:28:40 +0000 (14:28 +0000)
If trying to dial a non-existent queue, there would
be a segfault when attempting to access q->weight, even
though q was NULL. This problem was introduced during
the queue-reset merge and thus only affects trunk.

(closes issue #14643)
Reported by: alecdavis

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

apps/app_queue.c

index 6b7ddd5..f9cc878 100644 (file)
@@ -1826,11 +1826,13 @@ static struct call_queue *load_realtime_queue(const char *queuename)
                        ast_variables_destroy(queue_vars);
                }
                /* update the use_weight value if the queue's has gained or lost a weight */ 
-               if (!q->weight && prev_weight) {
-                       ast_atomic_fetchadd_int(&use_weight, -1);
-               }
-               if (q->weight && !prev_weight) {
-                       ast_atomic_fetchadd_int(&use_weight, +1);
+               if (q) {
+                       if (!q->weight && prev_weight) {
+                               ast_atomic_fetchadd_int(&use_weight, -1);
+                       }
+                       if (q->weight && !prev_weight) {
+                               ast_atomic_fetchadd_int(&use_weight, +1);
+                       }
                }
                /* Other cases will end up with the proper value for use_weight */
                ao2_unlock(queues);