From 36681dbbf8b0ca69d092220143f64f5f2adf4257 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Thu, 23 Jun 2022 01:33:03 -0700 Subject: [PATCH] 1. Fixed bug where global-tunnel.end() didn't clear the proxy 2. Broke infinite loop that could occur with circular referenced list 3. Added NULL check --- microscript/ILibDuktape_Helpers.c | 23 +++++++++++++---------- microscript/ILibDuktape_net.c | 12 ++++++++++-- microstack/ILibParsers.c | 26 ++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/microscript/ILibDuktape_Helpers.c b/microscript/ILibDuktape_Helpers.c index c701565..d8eae70 100644 --- a/microscript/ILibDuktape_Helpers.c +++ b/microscript/ILibDuktape_Helpers.c @@ -125,18 +125,21 @@ void Duktape_RunOnEventLoop_AbortSink(void *chain, void *user) void Duktape_RunOnEventLoop_Sink(void *chain, void *user) { Duktape_EventLoopDispatchData *tmp = (Duktape_EventLoopDispatchData*)user; - if (duk_ctx_is_alive(tmp->ctx) && duk_ctx_is_valid(tmp->nonce, tmp->ctx)) + if (tmp != NULL) { - // duk_context matches the intended context - if (tmp->handler != NULL) { tmp->handler(chain, tmp->user); } + if (duk_ctx_is_alive(tmp->ctx) && duk_ctx_is_valid(tmp->nonce, tmp->ctx)) + { + // duk_context matches the intended context + if (tmp->handler != NULL) { tmp->handler(chain, tmp->user); } + } + else + { + // duk_context does not match the intended context + Duktape_RunOnEventLoop_AbortSink(chain, user); + return; + } + ILibMemory_Free(tmp); } - else - { - // duk_context does not match the intended context - Duktape_RunOnEventLoop_AbortSink(chain, user); - return; - } - ILibMemory_Free(tmp); } #ifdef WIN32 void __stdcall Duktape_RunOnEventLoop_SanityCheck(ULONG_PTR u) diff --git a/microscript/ILibDuktape_net.c b/microscript/ILibDuktape_net.c index 604fcb4..45b58c2 100644 --- a/microscript/ILibDuktape_net.c +++ b/microscript/ILibDuktape_net.c @@ -1898,8 +1898,16 @@ void ILibDuktape_net_PUSH_net(duk_context *ctx, void *chain) } duk_ret_t ILibDuktape_globalTunnel_end(duk_context *ctx) { - duk_push_heap_stash(ctx); - duk_del_prop_string(ctx, -1, ILibDuktape_GlobalTunnel_Stash); + ILibDuktape_globalTunnel_data *data; + ILibHashtable tmp; + duk_push_this(ctx); + duk_get_prop_string(ctx, -1, ILibDuktape_GlobalTunnel_DataPtr); + data = (ILibDuktape_globalTunnel_data*)Duktape_GetBuffer(ctx, -1, NULL); + tmp = data->exceptionsTable; + ILibHashtable_Clear(tmp); + + memset(data, 0, sizeof(ILibDuktape_globalTunnel_data)); + data->exceptionsTable = tmp; return 0; } duk_ret_t ILibDuktape_globalTunnel_initialize(duk_context *ctx) diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index b5f1513..6e96b24 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -919,7 +919,8 @@ struct ILibLifeTime void *Reserved; char *CurrentTriggeredMetaData; - + + void *DeleteList; void *ObjectList; int ObjectCount; }; @@ -5218,7 +5219,7 @@ void *ILibQueue_DeQueue(ILibQueue q) void *node; node = ILibLinkedList_GetNode_Head((ILibLinkedList)q); - if (node!=NULL) + if (node!=NULL && ILibMemory_CanaryOK(node)) { RetVal = ILibLinkedList_GetDataFromNode(node); ILibLinkedList_Remove(node); @@ -7880,6 +7881,19 @@ void ILibLifeTime_Remove(void *LifeTimeToken, void *data) void *EventQueue; if (UPnPLifeTime == NULL || UPnPLifeTime->ObjectList == NULL) return; + + //// + //// Check to see if we are on the Microstack Thread, to see if we can simplify this + //// + //if (ILibIsRunningOnChainThread(UPnPLifeTime->ChainLink.ParentChain) == 0) + //{ + // // Not on the right thread, so we need to defer processing to the Microstack Thread + // ILibQueue_Lock(NULL); + + // ILibQueue_UnLock(NULL); + //} + + EventQueue = ILibQueue_Create(); ILibLinkedList_Lock(UPnPLifeTime->ObjectList); @@ -8194,6 +8208,14 @@ void* ILibLinkedList_GetNode_Tail(void *LinkedList) */ void* ILibLinkedList_GetNextNode(void *LinkedList_Node) { + if (ILibMemory_CanaryOK(LinkedList_Node)) + { + if (((struct ILibLinkedListNode*)LinkedList_Node)->Next == LinkedList_Node) + { + // There is a circular reference, so we need to break the loop + return(NULL); + } + } return(ILibMemory_CanaryOK(LinkedList_Node) ? ((struct ILibLinkedListNode*)LinkedList_Node)->Next : NULL); }