mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-18 16:42:54 +01:00
Merge bitcoin/bitcoin#28066: fuzz: Generate process_message targets individually
fa6245da60fuzz: Generate process_message targets individually (MarcoFalke)fa1471e575refactor: Remove duplicate allNetMessageTypesVec (MarcoFalke) Pull request description: Now that `LIMIT_TO_MESSAGE_TYPE` is a runtime setting after commit927b001502, it shouldn't hurt to also generate each message type individually. Something similar was done for the `rpc` target in commitcf4da5ec29. ACKs for top commit: stickies-v: re-crACKfa6245da60brunoerg: reACKfa6245da60Tree-SHA512: 8f3ec71bab89781f10820a0e027fcde8949f3333eb19a30315aaad6f90f5167028113cea255b2d60b700da817c7eaac20b7b4c92f931052d7f5c2f148d33aa5a
This commit is contained in:
@@ -12,47 +12,47 @@
|
|||||||
static std::atomic<bool> g_initial_block_download_completed(false);
|
static std::atomic<bool> g_initial_block_download_completed(false);
|
||||||
|
|
||||||
namespace NetMsgType {
|
namespace NetMsgType {
|
||||||
const char *VERSION="version";
|
const char* VERSION = "version";
|
||||||
const char *VERACK="verack";
|
const char* VERACK = "verack";
|
||||||
const char *ADDR="addr";
|
const char* ADDR = "addr";
|
||||||
const char *ADDRV2="addrv2";
|
const char* ADDRV2 = "addrv2";
|
||||||
const char *SENDADDRV2="sendaddrv2";
|
const char* SENDADDRV2 = "sendaddrv2";
|
||||||
const char *INV="inv";
|
const char* INV = "inv";
|
||||||
const char *GETDATA="getdata";
|
const char* GETDATA = "getdata";
|
||||||
const char *MERKLEBLOCK="merkleblock";
|
const char* MERKLEBLOCK = "merkleblock";
|
||||||
const char *GETBLOCKS="getblocks";
|
const char* GETBLOCKS = "getblocks";
|
||||||
const char *GETHEADERS="getheaders";
|
const char* GETHEADERS = "getheaders";
|
||||||
const char *TX="tx";
|
const char* TX = "tx";
|
||||||
const char *HEADERS="headers";
|
const char* HEADERS = "headers";
|
||||||
const char *BLOCK="block";
|
const char* BLOCK = "block";
|
||||||
const char *GETADDR="getaddr";
|
const char* GETADDR = "getaddr";
|
||||||
const char *MEMPOOL="mempool";
|
const char* MEMPOOL = "mempool";
|
||||||
const char *PING="ping";
|
const char* PING = "ping";
|
||||||
const char *PONG="pong";
|
const char* PONG = "pong";
|
||||||
const char *NOTFOUND="notfound";
|
const char* NOTFOUND = "notfound";
|
||||||
const char *FILTERLOAD="filterload";
|
const char* FILTERLOAD = "filterload";
|
||||||
const char *FILTERADD="filteradd";
|
const char* FILTERADD = "filteradd";
|
||||||
const char *FILTERCLEAR="filterclear";
|
const char* FILTERCLEAR = "filterclear";
|
||||||
const char *SENDHEADERS="sendheaders";
|
const char* SENDHEADERS = "sendheaders";
|
||||||
const char *FEEFILTER="feefilter";
|
const char* FEEFILTER = "feefilter";
|
||||||
const char *SENDCMPCT="sendcmpct";
|
const char* SENDCMPCT = "sendcmpct";
|
||||||
const char *CMPCTBLOCK="cmpctblock";
|
const char* CMPCTBLOCK = "cmpctblock";
|
||||||
const char *GETBLOCKTXN="getblocktxn";
|
const char* GETBLOCKTXN = "getblocktxn";
|
||||||
const char *BLOCKTXN="blocktxn";
|
const char* BLOCKTXN = "blocktxn";
|
||||||
const char *GETCFILTERS="getcfilters";
|
const char* GETCFILTERS = "getcfilters";
|
||||||
const char *CFILTER="cfilter";
|
const char* CFILTER = "cfilter";
|
||||||
const char *GETCFHEADERS="getcfheaders";
|
const char* GETCFHEADERS = "getcfheaders";
|
||||||
const char *CFHEADERS="cfheaders";
|
const char* CFHEADERS = "cfheaders";
|
||||||
const char *GETCFCHECKPT="getcfcheckpt";
|
const char* GETCFCHECKPT = "getcfcheckpt";
|
||||||
const char *CFCHECKPT="cfcheckpt";
|
const char* CFCHECKPT = "cfcheckpt";
|
||||||
const char *WTXIDRELAY="wtxidrelay";
|
const char* WTXIDRELAY = "wtxidrelay";
|
||||||
const char *SENDTXRCNCL="sendtxrcncl";
|
const char* SENDTXRCNCL = "sendtxrcncl";
|
||||||
} // namespace NetMsgType
|
} // namespace NetMsgType
|
||||||
|
|
||||||
/** All known message types. Keep this in the same order as the list of
|
/** All known message types. Keep this in the same order as the list of
|
||||||
* messages above and in protocol.h.
|
* messages above and in protocol.h.
|
||||||
*/
|
*/
|
||||||
const static std::string allNetMessageTypes[] = {
|
const static std::vector<std::string> g_all_net_message_types{
|
||||||
NetMsgType::VERSION,
|
NetMsgType::VERSION,
|
||||||
NetMsgType::VERACK,
|
NetMsgType::VERACK,
|
||||||
NetMsgType::ADDR,
|
NetMsgType::ADDR,
|
||||||
@@ -89,7 +89,6 @@ const static std::string allNetMessageTypes[] = {
|
|||||||
NetMsgType::WTXIDRELAY,
|
NetMsgType::WTXIDRELAY,
|
||||||
NetMsgType::SENDTXRCNCL,
|
NetMsgType::SENDTXRCNCL,
|
||||||
};
|
};
|
||||||
const static std::vector<std::string> allNetMessageTypesVec(std::begin(allNetMessageTypes), std::end(allNetMessageTypes));
|
|
||||||
|
|
||||||
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
|
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
|
||||||
{
|
{
|
||||||
@@ -182,7 +181,7 @@ std::string CInv::ToString() const
|
|||||||
|
|
||||||
const std::vector<std::string> &getAllNetMessageTypes()
|
const std::vector<std::string> &getAllNetMessageTypes()
|
||||||
{
|
{
|
||||||
return allNetMessageTypesVec;
|
return g_all_net_message_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -193,6 +193,42 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def transform_process_message_target(targets, src_dir):
|
||||||
|
"""Add a target per process message, and also keep ("process_message", {}) to allow for
|
||||||
|
cross-pollination, or unlimited search"""
|
||||||
|
|
||||||
|
p2p_msg_target = "process_message"
|
||||||
|
if (p2p_msg_target, {}) in targets:
|
||||||
|
lines = subprocess.run(
|
||||||
|
["git", "grep", "--function-context", "g_all_net_message_types{", src_dir / "src" / "protocol.cpp"],
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
).stdout.splitlines()
|
||||||
|
lines = [l.split("::", 1)[1].split(",")[0].lower() for l in lines if l.startswith("src/protocol.cpp- NetMsgType::")]
|
||||||
|
assert len(lines)
|
||||||
|
targets += [(p2p_msg_target, {"LIMIT_TO_MESSAGE_TYPE": m}) for m in lines]
|
||||||
|
return targets
|
||||||
|
|
||||||
|
|
||||||
|
def transform_rpc_target(targets, src_dir):
|
||||||
|
"""Add a target per RPC command, and also keep ("rpc", {}) to allow for cross-pollination,
|
||||||
|
or unlimited search"""
|
||||||
|
|
||||||
|
rpc_target = "rpc"
|
||||||
|
if (rpc_target, {}) in targets:
|
||||||
|
lines = subprocess.run(
|
||||||
|
["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", src_dir / "src" / "test" / "fuzz" / "rpc.cpp"],
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
).stdout.splitlines()
|
||||||
|
lines = [l.split("\"", 1)[1].split("\"")[0] for l in lines if l.startswith("src/test/fuzz/rpc.cpp- \"")]
|
||||||
|
assert len(lines)
|
||||||
|
targets += [(rpc_target, {"LIMIT_TO_RPC_COMMAND": r}) for r in lines]
|
||||||
|
return targets
|
||||||
|
|
||||||
|
|
||||||
def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
|
def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
|
||||||
"""Generates new corpus.
|
"""Generates new corpus.
|
||||||
|
|
||||||
@@ -200,20 +236,9 @@ def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
|
|||||||
{corpus_dir}.
|
{corpus_dir}.
|
||||||
"""
|
"""
|
||||||
logging.info("Generating corpus to {}".format(corpus_dir))
|
logging.info("Generating corpus to {}".format(corpus_dir))
|
||||||
rpc_target = "rpc"
|
targets = [(t, {}) for t in targets] # expand to add dictionary for target-specific env variables
|
||||||
has_rpc = rpc_target in targets
|
targets = transform_process_message_target(targets, Path(src_dir))
|
||||||
if has_rpc:
|
targets = transform_rpc_target(targets, Path(src_dir))
|
||||||
targets.remove(rpc_target)
|
|
||||||
targets = [(t, {}) for t in targets]
|
|
||||||
if has_rpc:
|
|
||||||
lines = subprocess.run(
|
|
||||||
["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", os.path.join(src_dir, "src", "test", "fuzz", "rpc.cpp")],
|
|
||||||
check=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
text=True,
|
|
||||||
).stdout.splitlines()
|
|
||||||
lines = [l.split("\"", 1)[1].split("\"")[0] for l in lines if l.startswith("src/test/fuzz/rpc.cpp- \"")]
|
|
||||||
targets += [(rpc_target, {"LIMIT_TO_RPC_COMMAND": r}) for r in lines]
|
|
||||||
|
|
||||||
def job(command, t, t_env):
|
def job(command, t, t_env):
|
||||||
logging.debug(f"Running '{command}'")
|
logging.debug(f"Running '{command}'")
|
||||||
|
|||||||
Reference in New Issue
Block a user