]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10189: [core] switch_core_add_state_handler runtime.state_handler_index may exceed...
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 5 Jun 2017 23:31:56 +0000 (18:31 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 5 Jun 2017 23:31:56 +0000 (18:31 -0500)
src/switch_core.c

index 0b8c51f1f736eaa8acf9f5e77822b35daf1a8c52..22b35ed63b06af26d5fdd57f7820d8b4b521a8c7 100644 (file)
@@ -310,12 +310,13 @@ SWITCH_DECLARE(int) switch_core_add_state_handler(const switch_state_handler_tab
        int index;
 
        switch_mutex_lock(runtime.global_mutex);
-       index = runtime.state_handler_index++;
+       index = runtime.state_handler_index;
 
-       if (runtime.state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {
+       if (index > (SWITCH_MAX_STATE_HANDLERS - 1)) {
                index = -1;
        } else {
                runtime.state_handlers[index] = state_handler;
+               runtime.state_handler_index++;
        }
 
        switch_mutex_unlock(runtime.global_mutex);