Browse Source

fixed segfaults on accessing temp objects vector buffers

cl-refactor
Arkady Paronyan 10 years ago
parent
commit
c161ddb66a
  1. 5
      alethzero/MainWin.cpp
  2. 3
      libdevcore/RLP.h
  3. 26
      libdevcrypto/TrieDB.h
  4. 9
      libethereum/BlockChain.cpp
  5. 4
      libethereum/Client.cpp
  6. 20
      test/crypto.cpp

5
alethzero/MainWin.cpp

@ -109,8 +109,9 @@ Main::Main(QWidget *parent) :
cerr << "State root: " << BlockChain::genesis().stateRoot << endl; cerr << "State root: " << BlockChain::genesis().stateRoot << endl;
cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl; cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl;
cerr << "Block RLP: " << RLP(BlockChain::createGenesisBlock()) << endl; auto block = BlockChain::createGenesisBlock();
cerr << "Block Hex: " << toHex(BlockChain::createGenesisBlock()) << endl; cerr << "Block RLP: " << RLP(block) << endl;
cerr << "Block Hex: " << toHex(BlockChain::createGenesisBlock()) << endl;
cerr << "Network protocol version: " << dev::eth::c_protocolVersion << endl; cerr << "Network protocol version: " << dev::eth::c_protocolVersion << endl;
cerr << "Client database version: " << dev::eth::c_databaseVersion << endl; cerr << "Client database version: " << dev::eth::c_databaseVersion << endl;

3
libdevcore/RLP.h

@ -307,6 +307,9 @@ private:
mutable unsigned m_lastIndex = (unsigned)-1; mutable unsigned m_lastIndex = (unsigned)-1;
mutable unsigned m_lastEnd = 0; mutable unsigned m_lastEnd = 0;
mutable bytesConstRef m_lastItem; mutable bytesConstRef m_lastItem;
/// Disable construction from rvalue
explicit RLP(bytes const&& _d) {}
}; };
/** /**

26
libdevcrypto/TrieDB.h

@ -552,12 +552,18 @@ template <class DB> bytes GenericTrieDB<DB>::mergeAt(RLP const& _orig, NibbleSli
auto sh = _k.shared(k); auto sh = _k.shared(k);
// std::cout << _k << " sh " << k << " = " << sh << std::endl; // std::cout << _k << " sh " << k << " = " << sh << std::endl;
if (sh) if (sh)
{
// shared stuff - cleve at disagreement. // shared stuff - cleve at disagreement.
return mergeAt(RLP(cleve(_orig, sh)), _k, _v, true); auto cleved = cleve(_orig, sh);
return mergeAt(RLP(cleved), _k, _v, true);
}
else else
{
// nothing shared - branch // nothing shared - branch
return mergeAt(RLP(branch(_orig)), _k, _v, true); auto branched = branch(_orig);
return mergeAt(RLP(branched), _k, _v, true);
}
} }
else else
{ {
@ -685,8 +691,11 @@ template <class DB> bytes GenericTrieDB<DB>::deleteAt(RLP const& _orig, NibbleSl
byte used = uniqueInUse(_orig, 16); byte used = uniqueInUse(_orig, 16);
if (used != 255) if (used != 255)
if (isTwoItemNode(_orig[used])) if (isTwoItemNode(_orig[used]))
return graft(RLP(merge(_orig, used))); {
auto merged = merge(_orig, used);
return graft(RLP(merged));
}
else else
return merge(_orig, used); return merge(_orig, used);
else else
@ -721,8 +730,11 @@ template <class DB> bytes GenericTrieDB<DB>::deleteAt(RLP const& _orig, NibbleSl
return r.out(); return r.out();
// yes; merge // yes; merge
if (isTwoItemNode(rlp[used])) if (isTwoItemNode(rlp[used]))
return graft(RLP(merge(rlp, used))); {
auto merged = merge(rlp, used);
return graft(RLP(merged));
}
else else
return merge(rlp, used); return merge(rlp, used);
} }

9
libethereum/BlockChain.cpp

@ -277,8 +277,10 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
auto pd = details(bi.parentHash); auto pd = details(bi.parentHash);
if (!pd) if (!pd)
{ {
cwarn << "Odd: details is returning false despite block known:" << RLP(pd.rlp()); auto pdata = pd.rlp();
cwarn << "Block:" << RLP(block(bi.parentHash)); cwarn << "Odd: details is returning false despite block known:" << RLP(pdata);
auto parentBlock = block(bi.parentHash);
cwarn << "Block:" << RLP(parentBlock);
} }
// Check it's not crazy // Check it's not crazy
@ -447,7 +449,8 @@ h256Set BlockChain::allUnclesFrom(h256 _parent) const
for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent) for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent)
{ {
ret.insert(p); // TODO: check: should this be details(p).parent? ret.insert(p); // TODO: check: should this be details(p).parent?
for (auto i: RLP(block(p))[2]) auto bl = block(p);
for (auto i: RLP(bl)[2])
ret.insert(sha3(i.data())); ret.insert(sha3(i.data()));
} }
return ret; return ret;

4
libethereum/Client.cpp

@ -36,7 +36,9 @@ using namespace p2p;
VersionChecker::VersionChecker(string const& _dbPath): VersionChecker::VersionChecker(string const& _dbPath):
m_path(_dbPath.size() ? _dbPath : Defaults::dbPath()) m_path(_dbPath.size() ? _dbPath : Defaults::dbPath())
{ {
m_ok = RLP(contents(m_path + "/protocol")).toInt<unsigned>(RLP::LaisezFaire) == c_protocolVersion && RLP(contents(m_path + "/database")).toInt<unsigned>(RLP::LaisezFaire) == c_databaseVersion; auto protocolContents = contents(m_path + "/protocol");
auto databaseContents = contents(m_path + "/database");
m_ok = RLP(protocolContents).toInt<unsigned>(RLP::LaisezFaire) == c_protocolVersion && RLP(databaseContents).toInt<unsigned>(RLP::LaisezFaire) == c_databaseVersion;
} }
void VersionChecker::setOk() void VersionChecker::setOk()

20
test/crypto.cpp

@ -46,12 +46,14 @@ BOOST_AUTO_TEST_CASE(crypto_tests)
t.nonce = 0; t.nonce = 0;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")); t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000; t.value = 1000;
cnote << RLP(t.rlp(false)); auto rlp = t.rlp(false);
cnote << toHex(t.rlp(false)); cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(false); cnote << t.sha3(false);
t.sign(p.secret()); t.sign(p.secret());
cnote << RLP(t.rlp(true)); rlp = t.rlp(true);
cnote << toHex(t.rlp(true)); cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(true); cnote << t.sha3(true);
BOOST_REQUIRE(t.sender() == p.address()); BOOST_REQUIRE(t.sender() == p.address());
} }
@ -72,12 +74,14 @@ int cryptoTest()
t.nonce = 0; t.nonce = 0;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b")); t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000; t.value = 1000;
cnote << RLP(t.rlp(false)); auto rlp = t.rlp(false);
cnote << toHex(t.rlp(false)); cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(false); cnote << t.sha3(false);
t.sign(p.secret()); t.sign(p.secret());
cnote << RLP(t.rlp(true)); rlp = t.rlp(true);
cnote << toHex(t.rlp(true)); cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(true); cnote << t.sha3(true);
assert(t.sender() == p.address()); assert(t.sender() == p.address());
} }

Loading…
Cancel
Save