]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
address http://jira.freeswitch.org/browse/FSCORE-6 We still need to test what the...
authorMichael Jerris <mike@jerris.com>
Thu, 26 Apr 2007 23:09:26 +0000 (23:09 +0000)
committerMichael Jerris <mike@jerris.com>
Thu, 26 Apr 2007 23:09:26 +0000 (23:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5024 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.h

index 3984354b3118b61889c5b195bef77cb9f0b83a7c..e957467dd4d38cb834e337cc17e912c68d7012b6 100644 (file)
@@ -623,6 +623,7 @@ JSObject *new_js_event(switch_event_t *event, char *name, JSContext * cx, JSObje
        return Event;
 }
 
+#define MAX_STACK_DEPTH 12
 
 static switch_status_t js_common_callback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
 {
@@ -639,6 +640,8 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
                return SWITCH_STATUS_FALSE;
        }
 
+       jss->stack_depth++;
+
        switch (itype) {
        case SWITCH_INPUT_TYPE_EVENT:
                if ((event = (switch_event_t *) input)) {
@@ -648,6 +651,7 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
                        }
                }
                if (!Event) {
+                       jss->stack_depth--;
                        return SWITCH_STATUS_FALSE;
                }
                break;
@@ -662,10 +666,17 @@ static switch_status_t js_common_callback(switch_core_session_t *session, void *
                argv[argc++] = cb_state->arg;
        }
 
+       if (jss->stack_depth > MAX_STACK_DEPTH) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Maximum recursive callback limit %d reached.\n", MAX_STACK_DEPTH);
+               jss->stack_depth--;
+               return SWITCH_STATUS_FALSE;
+       }
+
        JS_ResumeRequest(cb_state->cx, cb_state->saveDepth);
        JS_CallFunction(cb_state->cx, cb_state->obj, cb_state->function, argc, argv, &cb_state->ret);
        cb_state->saveDepth = JS_SuspendRequest(cb_state->cx);
 
+       jss->stack_depth--;
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -2037,6 +2048,7 @@ static JSObject *new_js_session(JSContext * cx, JSObject * obj, switch_core_sess
                jss->flags = flags;
                jss->cx = cx;
                jss->obj = session_obj;
+               jss->stack_depth = 0;
                if ((JS_SetPrivate(cx, session_obj, jss) &&
                         JS_DefineProperties(cx, session_obj, session_props) && JS_DefineFunctions(cx, session_obj, session_methods))) {
                        return session_obj;
index c45fa12183ef45dd176f3c258086333ccaf6391d..c625bf32900bf9b239bffb0085f95764d813c278 100644 (file)
@@ -129,6 +129,7 @@ struct js_session {
        unsigned int flags;
        switch_call_cause_t cause;
        JSFunction *on_hangup;
+       int stack_depth;
        switch_channel_state_t hook_state;
 };