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

Fix invalid memory access in CScript::operator+= #1846

Merged
merged 1 commit into from Jul 18, 2019

Conversation

sickpig
Copy link
Collaborator

@sickpig sickpig commented Jul 17, 2019

This is a port of bitcoin/bitcoin/pull/11284. The following is the original PR discussion:

This is a fix for #11114 -- invoking "s += s" gets turned into "s.insert(s.end(), s.begin(), s.end())" which can result in an invalid memory access is s.capacity() < 2*s.size() (because s gets resized and possibly moved, so s.begin() and s.end() become invalid references when reading the values to be appended).
    
The fix is straightforward: reserve enough space in advance, so that insert() doesn't need to resize and thus its arguments remain valid.
    
A simple test case is added as well; though you probably need to run it via valgrind to actually catch the problem when it's not fixed...

@sickpig
Copy link
Collaborator Author

sickpig commented Jul 17, 2019

For some reason Travis didn't trigger a travis run. will investigate.

@gandrewstone gandrewstone merged commit 1868b91 into BitcoinUnlimited:dev Jul 18, 2019
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.

None yet

3 participants