Skip to content

Commit 478c6cb

Browse files
committed
Narrow fuzz-step-finder exception handling to std::regex_error
catch (const std::exception&) silently swallowed std::bad_alloc and any other unexpected exception as if it were the expected, benign std::regex_error from a malformed pattern. Only std::regex_error is actually expected here; anything else (e.g. bad_alloc from runaway allocation on a pathological pattern) should propagate to libFuzzer instead of being reported as a successful run.
1 parent 469c075 commit 478c6cb

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

fuzz/fuzz_step_finder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// ./build-fuzz/bin/fuzz-step-finder crash-<hash>
3232

3333
#include <cstdint>
34+
#include <regex>
3435
#include <string>
3536
#include <string_view>
3637

@@ -68,11 +69,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
6869
cuke::internal::step_finder finder(feature_text);
6970
[[maybe_unused]] bool matched = finder.step_matches(pattern);
7071
}
71-
catch (const std::exception&)
72+
catch (const std::regex_error&)
7273
{
7374
// std::regex may legitimately throw std::regex_error on malformed
7475
// patterns produced from fuzzed definition text; that is expected,
75-
// recoverable behavior, not a bug.
76+
// recoverable behavior, not a bug. Deliberately narrower than
77+
// std::exception: other exceptions (e.g. std::bad_alloc from runaway
78+
// allocation on a pathological pattern) must propagate to libFuzzer
79+
// instead of being silently treated as a successful run.
7680
}
7781

7882
return 0;

0 commit comments

Comments
 (0)