Skip to content

Commit

Permalink
Fix invalid memory access in CScript::operator+=
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtowns authored and sickpig committed Jul 17, 2019
1 parent 1023f82 commit 89cd133
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ class CScript : public CScriptBase
CScript(const unsigned char *pbegin, const unsigned char *pend) : CScriptBase(pbegin, pend) {}
CScript &operator+=(const CScript &b)
{
reserve(size() + b.size());
insert(end(), b.begin(), b.end());
return *this;
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/script_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2543,4 +2543,21 @@ BOOST_AUTO_TEST_CASE(script_debugger)
BOOST_CHECK(stk[0][0] == 4);
}

BOOST_AUTO_TEST_CASE(script_can_append_self)
{
CScript s, d;

s = ScriptFromHex("00");
s += s;
d = ScriptFromHex("0000");
BOOST_CHECK(s == d);

// check doubling a script that's large enough to require reallocation
static const char hex[] = "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f";
s = CScript() << ParseHex(hex) << OP_CHECKSIG;
d = CScript() << ParseHex(hex) << OP_CHECKSIG << ParseHex(hex) << OP_CHECKSIG;
s += s;
BOOST_CHECK(s == d);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 89cd133

Please sign in to comment.