Skip to content

Commit 3f8f238

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#21849: fuzz: Limit toxic test globals to their respective scope
cf83b82 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 cf83b82: non-toxic is better than toxic! laanwj: Code review ACK cf83b82 Tree-SHA512: 5b3a37bcb36fce4160c94f877b2c07704527e3e1842092375c793d2eca77b996ae62889326094020855666bb34fa019fcfe92e8ff8430ce0372227f03ab2b907
2 parents a1c6434 + cf83b82 commit 3f8f238

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/test/fuzz/script_assets_test_minimizer.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ unsigned int ParseScriptFlags(const std::string& str)
133133
std::vector<std::string> words;
134134
boost::algorithm::split(words, str, boost::algorithm::is_any_of(","));
135135

136-
for (const std::string& word : words)
137-
{
136+
for (const std::string& word : words) {
138137
auto it = FLAG_NAMES.find(word);
139138
if (it == FLAG_NAMES.end()) throw std::runtime_error("Unknown verification flag " + word);
140139
flags |= it->second;
@@ -186,15 +185,19 @@ void Test(const std::string& str)
186185
}
187186
}
188187

189-
ECCVerifyHandle handle;
190-
191-
} // namespace
188+
void test_init()
189+
{
190+
static ECCVerifyHandle handle;
191+
}
192192

193-
FUZZ_TARGET_INIT_HIDDEN(script_assets_test_minimizer, FuzzFrameworkEmptyInitFun, /* hidden */ true)
193+
FUZZ_TARGET_INIT_HIDDEN(script_assets_test_minimizer, test_init, /* hidden */ true)
194194
{
195195
if (buffer.size() < 2 || buffer.back() != '\n' || buffer[buffer.size() - 2] != ',') return;
196196
const std::string str((const char*)buffer.data(), buffer.size() - 2);
197197
try {
198198
Test(str);
199-
} catch (const std::runtime_error&) {}
199+
} catch (const std::runtime_error&) {
200+
}
200201
}
202+
203+
} // namespace

0 commit comments

Comments
 (0)