Skip to content

Commit 38bfca6

Browse files
committed
Added comments referencing multiple CVEs in tests and production code.
This commit adds comments referencing multiple CVEs both in production and test code. CVEs covered in this commit: CVE-2010-5137 CVE-2010-5139 CVE-2010-5141 CVE-2012-1909 CVE-2012-2459 CVE-2012-3789 CVE-2018-17144
1 parent c7cfd20 commit 38bfca6

File tree

8 files changed

+16
-10
lines changed

8 files changed

+16
-10
lines changed

src/consensus/tx_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
1818
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
1919
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-txns-oversize");
2020

21-
// Check for negative or overflow output values
21+
// Check for negative or overflow output values (see CVE-2010-5139)
2222
CAmount nValueOut = 0;
2323
for (const auto& txout : tx.vout)
2424
{

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
25132513
}
25142514
AddOrphanTx(ptx, pfrom->GetId());
25152515

2516-
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
2516+
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded (see CVE-2012-3789)
25172517
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, gArgs.GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
25182518
unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx);
25192519
if (nEvicted > 0) {

src/script/interpreter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
334334
opcode == OP_MOD ||
335335
opcode == OP_LSHIFT ||
336336
opcode == OP_RSHIFT)
337-
return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); // Disabled opcodes.
337+
return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); // Disabled opcodes (CVE-2010-5137).
338338

339339
// With SCRIPT_VERIFY_CONST_SCRIPTCODE, OP_CODESEPARATOR in non-segwit script is rejected even in an unexecuted branch
340340
if (opcode == OP_CODESEPARATOR && sigversion == SigVersion::BASE && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE))
@@ -1483,6 +1483,8 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
14831483
return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
14841484
}
14851485

1486+
// scriptSig and scriptPubKey must be evaluated sequentially on the same stack
1487+
// rather than being simply concatenated (see CVE-2010-5141)
14861488
std::vector<std::vector<unsigned char> > stack, stackCopy;
14871489
if (!EvalScript(stack, scriptSig, flags, checker, SigVersion::BASE, serror))
14881490
// serror is set

src/test/data/script_tests.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,15 +829,16 @@
829829
["NOP", "2SWAP 1", "P2SH,STRICTENC", "INVALID_STACK_OPERATION"],
830830
["1", "2 3 2SWAP 1", "P2SH,STRICTENC", "INVALID_STACK_OPERATION"],
831831

832+
833+
["NOP", "SIZE 1", "P2SH,STRICTENC", "INVALID_STACK_OPERATION"],
834+
835+
["TEST DISABLED OP CODES (CVE-2010-5137)"],
832836
["'a' 'b'", "CAT", "P2SH,STRICTENC", "DISABLED_OPCODE", "CAT disabled"],
833837
["'a' 'b' 0", "IF CAT ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "CAT disabled"],
834838
["'abc' 1 1", "SUBSTR", "P2SH,STRICTENC", "DISABLED_OPCODE", "SUBSTR disabled"],
835839
["'abc' 1 1 0", "IF SUBSTR ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "SUBSTR disabled"],
836840
["'abc' 2 0", "IF LEFT ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "LEFT disabled"],
837841
["'abc' 2 0", "IF RIGHT ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "RIGHT disabled"],
838-
839-
["NOP", "SIZE 1", "P2SH,STRICTENC", "INVALID_STACK_OPERATION"],
840-
841842
["'abc'", "IF INVERT ELSE 1 ENDIF", "P2SH,STRICTENC", "DISABLED_OPCODE", "INVERT disabled"],
842843
["1 2 0 IF AND ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "AND disabled"],
843844
["1 2 0 IF OR ELSE 1 ENDIF", "NOP", "P2SH,STRICTENC", "DISABLED_OPCODE", "OR disabled"],

src/validation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18651865
// If such overwrites are allowed, coinbases and transactions depending upon those
18661866
// can be duplicated to remove the ability to spend the first instance -- even after
18671867
// being sent to another address.
1868-
// See BIP30 and http://r6.ca/blog/20120206T005236Z.html for more information.
1868+
// See BIP30, CVE-2012-1909, and http://r6.ca/blog/20120206T005236Z.html for more information.
18691869
// This logic is not necessary for memory pool transactions, as AcceptToMemoryPool
18701870
// already refuses previously-known transaction ids entirely.
18711871
// This rule was originally applied to all blocks with a timestamp after March 15, 2012, 0:00 UTC.
@@ -3136,6 +3136,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
31363136
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-cb-multiple", "more than one coinbase");
31373137

31383138
// Check transactions
3139+
// Must check for duplicate inputs (see CVE-2018-17144)
31393140
for (const auto& tx : block.vtx)
31403141
if (!CheckTransaction(*tx, state, true))
31413142
return state.Invalid(state.GetReason(), false, state.GetRejectCode(), state.GetRejectReason(),

test/functional/feature_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def run_test(self):
787787
#
788788
# Blocks are not allowed to contain a transaction whose id matches that of an earlier,
789789
# not-fully-spent transaction in the same chain. To test, make identical coinbases;
790-
# the second one should be rejected.
790+
# the second one should be rejected. See also CVE-2012-1909.
791791
#
792792
self.log.info("Reject a block with a transaction with a duplicate hash of a previous transaction (BIP30)")
793793
self.move_tip(60)

test/functional/mempool_accept.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def run_test(self):
212212
rawtxs=[tx.serialize().hex()],
213213
)
214214

215+
# The following two validations prevent overflow of the output amounts (see CVE-2010-5139).
215216
self.log.info('A transaction with too large output value')
216217
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
217218
tx.vout[0].nValue = 21000000 * COIN + 1

test/functional/p2p_invalid_block.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ def run_test(self):
5353
block_time = best_block["time"] + 1
5454

5555
# Use merkle-root malleability to generate an invalid block with
56-
# same blockheader.
56+
# same blockheader (CVE-2012-2459).
5757
# Manufacture a block with 3 transactions (coinbase, spend of prior
5858
# coinbase, spend of that spend). Duplicate the 3rd transaction to
5959
# leave merkle root and blockheader unchanged but invalidate the block.
60+
# For more information on merkle-root malleability see src/consensus/merkle.cpp.
6061
self.log.info("Test merkle root malleability.")
6162

6263
block2 = create_block(tip, create_coinbase(height), block_time)
@@ -81,7 +82,7 @@ def run_test(self):
8182

8283
node.p2p.send_blocks_and_test([block2], node, success=False, reject_reason='bad-txns-duplicate')
8384

84-
# Check transactions for duplicate inputs
85+
# Check transactions for duplicate inputs (CVE-2018-17144)
8586
self.log.info("Test duplicate input block.")
8687

8788
block2_orig.vtx[2].vin.append(block2_orig.vtx[2].vin[0])

0 commit comments

Comments
 (0)