5ca8ef2 libconsensus: Add input validation of flags (Wladimir J. van der Laan)
This commit is contained in:
parent
063bc55424
commit
61af31531a
@ -70,10 +70,19 @@ struct ECCryptoClosure
|
|||||||
ECCryptoClosure instance_of_eccryptoclosure;
|
ECCryptoClosure instance_of_eccryptoclosure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check that all specified flags are part of the libconsensus interface. */
|
||||||
|
static bool verify_flags(unsigned int flags)
|
||||||
|
{
|
||||||
|
return (flags & ~(dashconsensus_SCRIPT_FLAGS_VERIFY_ALL)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
int dashconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
|
int dashconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
|
||||||
const unsigned char *txTo , unsigned int txToLen,
|
const unsigned char *txTo , unsigned int txToLen,
|
||||||
unsigned int nIn, unsigned int flags, dashconsensus_error* err)
|
unsigned int nIn, unsigned int flags, dashconsensus_error* err)
|
||||||
{
|
{
|
||||||
|
if (!verify_flags(flags)) {
|
||||||
|
return dashconsensus_ERR_INVALID_FLAGS;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen);
|
TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen);
|
||||||
CTransaction tx(deserialize, stream);
|
CTransaction tx(deserialize, stream);
|
||||||
|
@ -39,6 +39,7 @@ typedef enum dashconsensus_error_t
|
|||||||
dashconsensus_ERR_TX_INDEX,
|
dashconsensus_ERR_TX_INDEX,
|
||||||
dashconsensus_ERR_TX_SIZE_MISMATCH,
|
dashconsensus_ERR_TX_SIZE_MISMATCH,
|
||||||
dashconsensus_ERR_TX_DESERIALIZE,
|
dashconsensus_ERR_TX_DESERIALIZE,
|
||||||
|
dashconsensus_ERR_INVALID_FLAGS,
|
||||||
} dashconsensus_error;
|
} dashconsensus_error;
|
||||||
|
|
||||||
/** Script verification flags */
|
/** Script verification flags */
|
||||||
@ -50,6 +51,9 @@ enum
|
|||||||
dashconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY = (1U << 4), // enforce NULLDUMMY (BIP147)
|
dashconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY = (1U << 4), // enforce NULLDUMMY (BIP147)
|
||||||
dashconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
|
dashconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
|
||||||
dashconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10), // enable CHECKSEQUENCEVERIFY (BIP112)
|
dashconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10), // enable CHECKSEQUENCEVERIFY (BIP112)
|
||||||
|
dashconsensus_SCRIPT_FLAGS_VERIFY_ALL = dashconsensus_SCRIPT_FLAGS_VERIFY_P2SH | dashconsensus_SCRIPT_FLAGS_VERIFY_DERSIG |
|
||||||
|
dashconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY | dashconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY |
|
||||||
|
dashconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Returns 1 if the input nIn of the serialized transaction pointed to by
|
/// Returns 1 if the input nIn of the serialized transaction pointed to by
|
||||||
|
@ -154,7 +154,10 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, co
|
|||||||
#if defined(HAVE_CONSENSUS_LIB)
|
#if defined(HAVE_CONSENSUS_LIB)
|
||||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
stream << tx2;
|
stream << tx2;
|
||||||
BOOST_CHECK_MESSAGE(dashconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, flags, NULL) == expect,message);
|
int libconsensus_flags = flags & dashconsensus_SCRIPT_FLAGS_VERIFY_ALL;
|
||||||
|
if (libconsensus_flags == flags) {
|
||||||
|
BOOST_CHECK_MESSAGE(dashconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, NULL) == expect,message);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user