Commit 1bb7c1fb authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix possible segv in Function shared proxy

Summary:
[Folly] Fix possible segv in `Function` shared proxy when invoking the (public!) `nullptr`-taking ctor.

This proxy is used when converting `folly::Function` to `std::function` with shared state.

Reviewed By: ot

Differential Revision: D18517365

fbshipit-source-id: c414c1d1ae2b4f30ffa3269b216be07fedbf838c
parent c9bd77f1
......@@ -330,6 +330,9 @@ class FunctionTraitsSharedProxy {
explicit FunctionTraitsSharedProxy(Function<F>&& func)
: sp_(std::make_shared<Function<F>>(std::move(func))) {}
R operator()(A&&... args) const {
if (!sp_) {
throw_exception<std::bad_function_call>();
}
return (*sp_)(static_cast<A&&>(args)...);
}
......
......@@ -1092,6 +1092,11 @@ TEST(Function, asSharedProxy_args_const) {
EXPECT_EQ(562, spcopy(5, 6));
}
TEST(Function, asSharedProxy_nullptr) {
auto sp = folly::Function<int(int, int) const>::SharedProxy(nullptr);
EXPECT_THROW(sp(3, 4), std::bad_function_call);
}
TEST(Function, NoAllocatedMemoryAfterMove) {
Functor<int, 100> foo;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment