blob: 7c979dfea74caf2c5d48e2008cc41c14da0809d2 [file] [log] [blame]
Vitaly Bukab93a1462017-01-07 01:52:581// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <cstddef>
16#include <cstdint>
17
Vitaly Buka8da52812017-01-20 23:14:4418#include "libfuzzer_example.pb.h" // NOLINT
Vitaly Buka9dd2f8e2017-01-13 08:48:3119#include "src/libfuzzer_protobuf_mutator.h"
Vitaly Bukab93a1462017-01-07 01:52:5820
Vitaly Bukab93a1462017-01-07 01:52:5821using libfuzzer_example::Msg;
22
Vitaly Bukab93a1462017-01-07 01:52:5823extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size,
24 size_t max_size, unsigned int seed) {
Vitaly Buka8c64f9b2017-01-12 19:14:0225 libfuzzer_example::Msg message;
26 return protobuf_mutator::MutateTextMessage(data, size, max_size, seed,
27 &message);
Vitaly Bukab93a1462017-01-07 01:52:5828}
29
30extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
Vitaly Buka8c64f9b2017-01-12 19:14:0231 libfuzzer_example::Msg message;
32 protobuf_mutator::ParseTextMessage(data, size, &message);
Vitaly Bukab93a1462017-01-07 01:52:5833
34 // Emulate a bug.
35 if (message.optional_uint64() > 100 &&
36 !std::isnan(message.optional_float()) &&
37 fabs(message.optional_float()) > 1000 &&
38 fabs(message.optional_float()) < 1E10) {
39 abort();
40 }
41
42 return 0;
43}