Skip to content

Commit 34cdc41

Browse files
committed
String conversions uint256 -> uint256S
If uint256() constructor takes a string, uint256(0) will become dangerous when uint256 does not take integers anymore (it will go through std::string(const char*) making a NULL string, and the explicit keyword is no help).
1 parent 2eae315 commit 34cdc41

File tree

11 files changed

+66
-66
lines changed

11 files changed

+66
-66
lines changed

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
191191
string strTxid = strInput.substr(0, pos);
192192
if ((strTxid.size() != 64) || !IsHex(strTxid))
193193
throw runtime_error("invalid TX input txid");
194-
uint256 txid(strTxid);
194+
uint256 txid(uint256S(strTxid));
195195

196196
static const unsigned int minTxOutSz = 9;
197197
static const unsigned int maxVout = MAX_BLOCK_SIZE / minTxOutSz;

src/chainparams.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data
5454
*/
5555
static Checkpoints::MapCheckpoints mapCheckpoints =
5656
boost::assign::map_list_of
57-
( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
58-
( 33333, uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
59-
( 74000, uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20"))
60-
(105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97"))
61-
(134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
62-
(168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763"))
63-
(193000, uint256("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317"))
64-
(210000, uint256("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e"))
65-
(216116, uint256("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e"))
66-
(225430, uint256("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932"))
67-
(250000, uint256("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214"))
68-
(279000, uint256("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40"))
69-
(295000, uint256("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983"))
57+
( 11111, uint256S("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
58+
( 33333, uint256S("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
59+
( 74000, uint256S("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20"))
60+
(105000, uint256S("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97"))
61+
(134444, uint256S("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
62+
(168000, uint256S("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763"))
63+
(193000, uint256S("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317"))
64+
(210000, uint256S("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e"))
65+
(216116, uint256S("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e"))
66+
(225430, uint256S("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932"))
67+
(250000, uint256S("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214"))
68+
(279000, uint256S("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40"))
69+
(295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983"))
7070
;
7171
static const Checkpoints::CCheckpointData data = {
7272
&mapCheckpoints,
@@ -78,7 +78,7 @@ static const Checkpoints::CCheckpointData data = {
7878

7979
static Checkpoints::MapCheckpoints mapCheckpointsTestnet =
8080
boost::assign::map_list_of
81-
( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
81+
( 546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70"))
8282
;
8383
static const Checkpoints::CCheckpointData dataTestnet = {
8484
&mapCheckpointsTestnet,
@@ -89,7 +89,7 @@ static const Checkpoints::CCheckpointData dataTestnet = {
8989

9090
static Checkpoints::MapCheckpoints mapCheckpointsRegtest =
9191
boost::assign::map_list_of
92-
( 0, uint256("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"))
92+
( 0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"))
9393
;
9494
static const Checkpoints::CCheckpointData dataRegtest = {
9595
&mapCheckpointsRegtest,
@@ -149,8 +149,8 @@ class CMainParams : public CChainParams {
149149
genesis.nNonce = 2083236893;
150150

151151
hashGenesisBlock = genesis.GetHash();
152-
assert(hashGenesisBlock == uint256("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
153-
assert(genesis.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
152+
assert(hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
153+
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
154154

155155
vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be"));
156156
vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me"));
@@ -208,7 +208,7 @@ class CTestNetParams : public CMainParams {
208208
genesis.nTime = 1296688602;
209209
genesis.nNonce = 414098458;
210210
hashGenesisBlock = genesis.GetHash();
211-
assert(hashGenesisBlock == uint256("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
211+
assert(hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
212212

213213
vFixedSeeds.clear();
214214
vSeeds.clear();
@@ -265,7 +265,7 @@ class CRegTestParams : public CTestNetParams {
265265
genesis.nNonce = 2;
266266
hashGenesisBlock = genesis.GetHash();
267267
nDefaultPort = 18444;
268-
assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
268+
assert(hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
269269

270270
vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds.
271271
vSeeds.clear(); //! Regtest mode doesn't have any DNS seeds.

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,8 +1738,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17381738
// two in the chain that violate it. This prevents exploiting the issue against nodes in their
17391739
// initial block download.
17401740
bool fEnforceBIP30 = (!pindex->phashBlock) || // Enforce on CreateNewBlock invocations which don't have a hash.
1741-
!((pindex->nHeight==91842 && pindex->GetBlockHash() == uint256("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) ||
1742-
(pindex->nHeight==91880 && pindex->GetBlockHash() == uint256("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")));
1741+
!((pindex->nHeight==91842 && pindex->GetBlockHash() == uint256S("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) ||
1742+
(pindex->nHeight==91880 && pindex->GetBlockHash() == uint256S("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")));
17431743
if (fEnforceBIP30) {
17441744
BOOST_FOREACH(const CTransaction& tx, block.vtx) {
17451745
const CCoins* coins = view.AccessCoins(tx.GetHash());

src/qt/coincontroldialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void CoinControlDialog::showMenu(const QPoint &point)
213213
if (item->text(COLUMN_TXHASH).length() == 64) // transaction hash is 64 characters (this means its a child node, so its not a parent node in tree mode)
214214
{
215215
copyTransactionHashAction->setEnabled(true);
216-
if (model->isLockedCoin(uint256(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt()))
216+
if (model->isLockedCoin(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt()))
217217
{
218218
lockAction->setEnabled(false);
219219
unlockAction->setEnabled(true);
@@ -272,7 +272,7 @@ void CoinControlDialog::lockCoin()
272272
if (contextMenuItem->checkState(COLUMN_CHECKBOX) == Qt::Checked)
273273
contextMenuItem->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
274274

275-
COutPoint outpt(uint256(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt());
275+
COutPoint outpt(uint256S(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt());
276276
model->lockCoin(outpt);
277277
contextMenuItem->setDisabled(true);
278278
contextMenuItem->setIcon(COLUMN_CHECKBOX, SingleColorIcon(":/icons/lock_closed"));
@@ -282,7 +282,7 @@ void CoinControlDialog::lockCoin()
282282
// context menu action: unlock coin
283283
void CoinControlDialog::unlockCoin()
284284
{
285-
COutPoint outpt(uint256(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt());
285+
COutPoint outpt(uint256S(contextMenuItem->text(COLUMN_TXHASH).toStdString()), contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt());
286286
model->unlockCoin(outpt);
287287
contextMenuItem->setDisabled(false);
288288
contextMenuItem->setIcon(COLUMN_CHECKBOX, QIcon());
@@ -388,7 +388,7 @@ void CoinControlDialog::viewItemChanged(QTreeWidgetItem* item, int column)
388388
{
389389
if (column == COLUMN_CHECKBOX && item->text(COLUMN_TXHASH).length() == 64) // transaction hash is 64 characters (this means its a child node, so its not a parent node in tree mode)
390390
{
391-
COutPoint outpt(uint256(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt());
391+
COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), item->text(COLUMN_VOUT_INDEX).toUInt());
392392

393393
if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked)
394394
coinControl->UnSelect(outpt);

src/rpcblockchain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Value getblock(const Array& params, bool fHelp)
278278
);
279279

280280
std::string strHash = params[0].get_str();
281-
uint256 hash(strHash);
281+
uint256 hash(uint256S(strHash));
282282

283283
bool fVerbose = true;
284284
if (params.size() > 1)
@@ -383,7 +383,7 @@ Value gettxout(const Array& params, bool fHelp)
383383
Object ret;
384384

385385
std::string strHash = params[0].get_str();
386-
uint256 hash(strHash);
386+
uint256 hash(uint256S(strHash));
387387
int n = params[1].get_int();
388388
bool fMempool = true;
389389
if (params.size() > 2)
@@ -619,7 +619,7 @@ Value invalidateblock(const Array& params, bool fHelp)
619619
);
620620

621621
std::string strHash = params[0].get_str();
622-
uint256 hash(strHash);
622+
uint256 hash(uint256S(strHash));
623623
CValidationState state;
624624

625625
{
@@ -658,7 +658,7 @@ Value reconsiderblock(const Array& params, bool fHelp)
658658
);
659659

660660
std::string strHash = params[0].get_str();
661-
uint256 hash(strHash);
661+
uint256 hash(uint256S(strHash));
662662
CValidationState state;
663663

664664
{

src/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ Value lockunspent(const Array& params, bool fHelp)
19021902
if (nOutput < 0)
19031903
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
19041904

1905-
COutPoint outpt(uint256(txid), nOutput);
1905+
COutPoint outpt(uint256S(txid), nOutput);
19061906

19071907
if (fUnlock)
19081908
pwalletMain->UnlockCoin(outpt);

src/script/interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ class CTransactionSignatureSerializer {
10301030

10311031
uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
10321032
{
1033-
static const uint256 one("0000000000000000000000000000000000000000000000000000000000000001");
1033+
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
10341034
if (nIn >= txTo.vin.size()) {
10351035
// nIn out of range
10361036
return one;

src/test/Checkpoints_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ BOOST_AUTO_TEST_SUITE(Checkpoints_tests)
1818

1919
BOOST_AUTO_TEST_CASE(sanity)
2020
{
21-
uint256 p11111 = uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d");
22-
uint256 p134444 = uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe");
21+
uint256 p11111 = uint256S("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d");
22+
uint256 p134444 = uint256S("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe");
2323
BOOST_CHECK(Checkpoints::CheckBlock(11111, p11111));
2424
BOOST_CHECK(Checkpoints::CheckBlock(134444, p134444));
2525

0 commit comments

Comments
 (0)