blob: e497fe91d525eae0be69d85aac69e7ffa22075a0 [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.
Vitaly Buka24434412017-01-31 01:42:0535 if (message.optional_bool() && message.optional_string() == "FooBar") {
Vitaly Bukab93a1462017-01-07 01:52:5836 abort();
37 }
38
39 return 0;
40}