From: bert hubert Date: Tue, 10 Oct 2017 10:48:55 +0000 (+0200) Subject: Fix crash on older boost when receiving an exception from an MThread X-Git-Tag: rec-4.1.0-rc2~46^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=580f51c22e2443bf5abe30f8d7e770fc30511a92;p=thirdparty%2Fpdns.git Fix crash on older boost when receiving an exception from an MThread for older boost fcontext versions, we would return a boolean that said 'we caught an exception for you and stored it in ctx', but we would not actually retrieve the origin ctx, and then blindly attempt to rethrow the exception (not) stored in the ctx we did have, leading to a crash. We now send back the actual ctx, and check it for a stored exception. --- diff --git a/pdns/mtasker_fcontext.cc b/pdns/mtasker_fcontext.cc index 362a2f797f..0ab87b6f6c 100644 --- a/pdns/mtasker_fcontext.cc +++ b/pdns/mtasker_fcontext.cc @@ -152,7 +152,7 @@ threadWrapper (transfer_t const t) { #if BOOST_VERSION < 106100 jump_fcontext (reinterpret_cast(&ctx->uc_mcontext), static_cast(next_ctx), - static_cast(ctx->exception)); + reinterpret_cast(ctx)); #else jump_fcontext (static_cast(next_ctx), 0); #endif @@ -189,10 +189,12 @@ pdns_swapcontext or we switch back to pdns_swapcontext(), in both case we will be returning from a call to jump_fcontext(). */ #if BOOST_VERSION < 106100 - if (jump_fcontext (reinterpret_cast(&octx.uc_mcontext), - static_cast(ctx.uc_mcontext), 0)) { - std::rethrow_exception (ctx.exception); - } + intptr_t ptr = jump_fcontext(reinterpret_cast(&octx.uc_mcontext), + static_cast(ctx.uc_mcontext), 0); + + auto origctx = reinterpret_cast(ptr); + if(origctx && origctx->exception) + std::rethrow_exception (origctx->exception); #else transfer_t res = jump_fcontext (static_cast(ctx.uc_mcontext), &octx.uc_mcontext); if (res.data) {