Vitaly Buka | b93a146 | 2017-01-07 01:52:58 | [diff] [blame] | 1 | // 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 Buka | 5b1a003 | 2017-02-17 08:06:06 | [diff] [blame] | 18 | #include "examples/libfuzzer/libfuzzer_example.pb.h" |
Vitaly Buka | 9dd2f8e | 2017-01-13 08:48:31 | [diff] [blame] | 19 | #include "src/libfuzzer_protobuf_mutator.h" |
Vitaly Buka | b93a146 | 2017-01-07 01:52:58 | [diff] [blame] | 20 | |
Vitaly Buka | b93a146 | 2017-01-07 01:52:58 | [diff] [blame] | 21 | using libfuzzer_example::Msg; |
| 22 | |
Vitaly Buka | b93a146 | 2017-01-07 01:52:58 | [diff] [blame] | 23 | extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, |
| 24 | size_t max_size, unsigned int seed) { |
Vitaly Buka | 8c64f9b | 2017-01-12 19:14:02 | [diff] [blame] | 25 | libfuzzer_example::Msg message; |
| 26 | return protobuf_mutator::MutateTextMessage(data, size, max_size, seed, |
| 27 | &message); |
Vitaly Buka | b93a146 | 2017-01-07 01:52:58 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
Vitaly Buka | 8c64f9b | 2017-01-12 19:14:02 | [diff] [blame] | 31 | libfuzzer_example::Msg message; |
| 32 | protobuf_mutator::ParseTextMessage(data, size, &message); |
Vitaly Buka | b93a146 | 2017-01-07 01:52:58 | [diff] [blame] | 33 | |
| 34 | // Emulate a bug. |
Vitaly Buka | 2443441 | 2017-01-31 01:42:05 | [diff] [blame] | 35 | if (message.optional_bool() && message.optional_string() == "FooBar") { |
Vitaly Buka | b93a146 | 2017-01-07 01:52:58 | [diff] [blame] | 36 | abort(); |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |