Skip to content

Fix UB due to dangling references in try/catch - #94

Merged
djowel merged 2 commits into
boostorg:developfrom
mgaunard:try_catch_ref_ub
Apr 8, 2020
Merged

djowel merged 2 commits into
boostorg:developfrom
mgaunard:try_catch_ref_ub

Conversation

@mgaunard

Copy link
Copy Markdown
Contributor

No description provided.

@djowel

djowel commented Mar 22, 2020

Copy link
Copy Markdown
Collaborator

LGTM. Waiting for CI to cycle (asuming it will :-)

@mgaunard

mgaunard commented Apr 6, 2020

Copy link
Copy Markdown
Contributor Author

Can we get this in 1.73 please?

@Kojoley

Kojoley commented Apr 6, 2020

Copy link
Copy Markdown
Contributor

@mgaunard Your changes look reasonable, but could you maybe add some tests that show asan fails before the PR? I have added asan to the CI and it currently did not find issues, and I have not come with a reproducer myself.

@mgaunard

mgaunard commented Apr 7, 2020 •

Copy link
Copy Markdown
Contributor Author

I do not think I will have the time to do a proper one before tomorrow the deadline for boost 1.73.

ASan is a tool that can help in finding bugs, it certainly cannot act as a control to check whether bugs are present or not, so I'm not sure what value you're expecting to get there.
The bug itself is quite obvious from a glance at the code, and to be honest I'm quite concerned this went past the review process.

try_catch itself has no tests as-is.
I suppose an easy example would be something like this (not tested)

#include <boost/phoenix.hpp>
#include <cassert>

auto make_func()
{
    namespace phoenix = boost::phoenix;
    using namespace phoenix::placeholders;
    return phoenix::try_[phoenix::throw_(arg1)].catch_all[phoenix::ref(arg2) = true];
}

int main()
{
    auto const f = make_func();

    bool thrown = false;
    f(42, thrown);
    assert(thrown == true);
}

Clearly the "throw arg1" and "arg2 = true" sub-expressions don't exist anymore when f is called. I made it into a separate function returning another function to increase the chances of ASan detecting it.

@djowel

djowel commented Apr 8, 2020

Copy link
Copy Markdown
Collaborator

I'll have this merged. Let's deal with the test later.

@djowel
djowel merged commit 7e6e0e4 into boostorg:develop Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants