]> granicus.if.org Git - pdns/commitdiff
Fix crash on older boost when receiving an exception from an MThread
authorbert hubert <bert.hubert@netherlabs.nl>
Tue, 10 Oct 2017 10:48:55 +0000 (12:48 +0200)
committerbert hubert <bert.hubert@powerdns.com>
Tue, 10 Oct 2017 13:38:25 +0000 (15:38 +0200)
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.

pdns/mtasker_fcontext.cc

index 362a2f797fc507a4e7e443ada474bb7721072957..0ab87b6f6cc38c66dbd309ebadfb3710b5c028b9 100644 (file)
@@ -152,7 +152,7 @@ threadWrapper (transfer_t const t) {
 #if BOOST_VERSION < 106100
     jump_fcontext (reinterpret_cast<fcontext_t*>(&ctx->uc_mcontext),
                    static_cast<fcontext_t>(next_ctx),
-                   static_cast<bool>(ctx->exception));
+                   reinterpret_cast<intptr_t>(ctx));
 #else
     jump_fcontext (static_cast<fcontext_t>(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<fcontext_t*>(&octx.uc_mcontext),
-                       static_cast<fcontext_t>(ctx.uc_mcontext), 0)) {
-        std::rethrow_exception (ctx.exception);
-    }
+    intptr_t ptr = jump_fcontext(reinterpret_cast<fcontext_t*>(&octx.uc_mcontext),
+                                 static_cast<fcontext_t>(ctx.uc_mcontext), 0);
+
+    auto origctx = reinterpret_cast<pdns_ucontext_t*>(ptr);
+    if(origctx && origctx->exception)
+        std::rethrow_exception (origctx->exception);
 #else
   transfer_t res = jump_fcontext (static_cast<fcontext_t>(ctx.uc_mcontext), &octx.uc_mcontext);
   if (res.data) {