Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang UBSAN and sequence_stack #14

Closed
alextibbles opened this issue Jul 12, 2020 · 1 comment
Closed

clang UBSAN and sequence_stack #14

alextibbles opened this issue Jul 12, 2020 · 1 comment

Comments

@alextibbles
Copy link

With clang-10 default set of UBSAN checks, the following gets triggered:
/usr/include/boost/xpressive/detail/utility/sequence_stack.hpp:217:21: runtime error: applying non-zero offset 4 to null pointer

#include <boost/xpressive/detail/utility/sequence_stack.hpp>

int main() {
	boost::xpressive::detail::sequence_stack<int> s;
	s.push_sequence(1, 42);
	return 0;
}

The following patch avoids the sanitizer error:

216,220c216,217
<         // Advance the high-water mark
<         this->curr_ += count;
< 
<         // Check to see if we have overflowed this buffer
<         if(std::less<void*>()(this->end_, this->curr_))
---
>         // Check to see if we would overflow this buffer
>         if((nullptr == ptr) || (std::less<void*>()(this->end_, ptr + count)))
222,224d218
<             // oops, back this out.
<             this->curr_ = ptr;
< 
227a222,224
>         
>         // Advance the high-water mark
>         this->curr_ += count;

Apologies, I couldn't find where the CI output for boost.org is published to see if this shows up in existing tests.
Reproducer attached:
sequence_stack_ubsan.zip

@alextibbles
Copy link
Author

Looks like this is already fixed in develop.

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

No branches or pull requests

1 participant