From 8f8936851ae5e7d2ba7eb5158f78d4e90d6a1152 Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Thu, 21 Jul 2022 14:36:01 +0100 Subject: [PATCH] Added fuzzer. This is first step in merging work from OSS-Fuzz into upstream. (#2548) --- cpp/test/phonenumbers/fuzz_phone.cc | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cpp/test/phonenumbers/fuzz_phone.cc diff --git a/cpp/test/phonenumbers/fuzz_phone.cc b/cpp/test/phonenumbers/fuzz_phone.cc new file mode 100644 index 000000000..a63d747a9 --- /dev/null +++ b/cpp/test/phonenumbers/fuzz_phone.cc @@ -0,0 +1,48 @@ +/* Copyright 2020 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#include "phonenumbers/phonenumbermatcher.h" +#include +#include + +#include + +#include "phonenumbers/base/basictypes.h" +#include "phonenumbers/base/memory/scoped_ptr.h" +#include "phonenumbers/base/memory/singleton.h" +#include "phonenumbers/default_logger.h" +#include "phonenumbers/phonenumber.h" +#include "phonenumbers/phonenumber.pb.h" +#include "phonenumbers/phonenumbermatch.h" +#include "phonenumbers/phonenumberutil.h" +#include "phonenumbers/stringutil.h" + +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider fuzzed_data(data, size); + + std::string input = fuzzed_data.ConsumeRandomLengthString(); + std::string input2 = fuzzed_data.ConsumeRandomLengthString(); + + i18n::phonenumbers::PhoneNumberUtil *phone_util = i18n::phonenumbers::PhoneNumberUtil::GetInstance(); + i18n::phonenumbers::PhoneNumber parsed; + + phone_util->Parse(input, input2, &parsed); + phone_util->IsValidNumber(parsed); + phone_util->GetCountryCodeForRegion(input); + + return 0; +}