Merge bitcoin/bitcoin#21849: fuzz: Limit toxic test globals to their respective scope

cf83b82cf0 fuzz: Limit toxic test globals to their respective scope (MarcoFalke)

Pull request description:

  Globals in one fuzz target are toxic to all other fuzz targets, because we link all fuzz targets into one binary. Any code called by constructing the global will affect all other targets. This leads to incorrect coverage stats, false-positive crashes, ...

ACKs for top commit:
  practicalswift:
    cr ACK cf83b82cf04a57223ebed74b8935e56f74ed721b: non-toxic is better than toxic!
  laanwj:
    Code review ACK cf83b82cf0

Tree-SHA512: 5b3a37bcb36fce4160c94f877b2c07704527e3e1842092375c793d2eca77b996ae62889326094020855666bb34fa019fcfe92e8ff8430ce0372227f03ab2b907
pull/826/head
MarcoFalke 4 years ago
commit 3f8f238deb
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

@ -133,8 +133,7 @@ unsigned int ParseScriptFlags(const std::string& str)
std::vector<std::string> words;
boost::algorithm::split(words, str, boost::algorithm::is_any_of(","));
for (const std::string& word : words)
{
for (const std::string& word : words) {
auto it = FLAG_NAMES.find(word);
if (it == FLAG_NAMES.end()) throw std::runtime_error("Unknown verification flag " + word);
flags |= it->second;
@ -186,15 +185,19 @@ void Test(const std::string& str)
}
}
ECCVerifyHandle handle;
} // namespace
void test_init()
{
static ECCVerifyHandle handle;
}
FUZZ_TARGET_INIT_HIDDEN(script_assets_test_minimizer, FuzzFrameworkEmptyInitFun, /* hidden */ true)
FUZZ_TARGET_INIT_HIDDEN(script_assets_test_minimizer, test_init, /* hidden */ true)
{
if (buffer.size() < 2 || buffer.back() != '\n' || buffer[buffer.size() - 2] != ',') return;
const std::string str((const char*)buffer.data(), buffer.size() - 2);
try {
Test(str);
} catch (const std::runtime_error&) {}
} catch (const std::runtime_error&) {
}
}
} // namespace

Loading…
Cancel
Save