Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions icu4c/source/test/fuzzer/break_iterator_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::memcpy(fuzzbuff.get(), data, unistr_size * 2);

UText* fuzzstr = utext_openUChars(nullptr, fuzzbuff.get(), unistr_size, &status);
if (U_FAILURE(status) || fuzzstr == nullptr) {
return 0;
}

const icu::Locale& locale = GetRandomLocale(rnd16);

Expand All @@ -54,6 +57,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
break;
}

if (bi == nullptr || U_FAILURE(status)) {
utext_close(fuzzstr);
return 0;
}

bi->setText(fuzzstr, status);

if (U_FAILURE(status)) {
Expand All @@ -65,6 +73,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {

utext_close(fuzzstr);

// Reset status before second round of BreakIterator creation.
status = U_ZERO_ERROR;

std::string str(reinterpret_cast<const char*>(data), size);
icu::Locale locale2(str.c_str()); // ensure null-termination by c_str()
switch (rnd8 % 5) {
Expand Down