From a131e5232e63be00718387e5c3dec0353a9a43c7 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 25 Mar 2013 13:11:25 -0700 Subject: [PATCH] Handle invalid Continuation state at start time In an unlikely situation a user of ext_asio may tamper with Continuation before passing it to the ext_asio extension. Let's fail with an exception if this happens. Previously, a user bug would stay unnoticed, but would not harm the ext_asio code. This check will be needed once we implement optimistic execution. With optimistic execution, we iterate continuation and defer construction of ContinuationWaitHandle until the first blocking event occurs. During this phase, a standard dependency loop detection is skipped and the code would try to iterate a continuation that is already being iterated. --- hphp/runtime/ext/asio/continuation_wait_handle.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hphp/runtime/ext/asio/continuation_wait_handle.cpp b/hphp/runtime/ext/asio/continuation_wait_handle.cpp index 7d7daaa54..385e0cced 100644 --- a/hphp/runtime/ext/asio/continuation_wait_handle.cpp +++ b/hphp/runtime/ext/asio/continuation_wait_handle.cpp @@ -71,6 +71,14 @@ Object c_ContinuationWaitHandle::ti_start(const char* cls, CObjRef continuation) return cont->m_waitHandle; } + if (UNLIKELY(cont->m_index != -1)) { + Object e(SystemLib::AllocInvalidOperationExceptionObject( + cont->m_running + ? "Encountered an attempt to start currently running continuation" + : "Encountered an attempt to start tainted continuation")); + throw e; + } + p_ContinuationWaitHandle wh = NEWOBJ(c_ContinuationWaitHandle)(); wh->start(cont, depth + 1); if (UNLIKELY(session->hasOnStartedCallback())) {