| Corbin Souffrant | 84f5c0f | 2020-06-26 00:42:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <fuzzer/FuzzedDataProvider.h> |
| 18 | |
| Corbin Souffrant | 84f5c0f | 2020-06-26 00:42:43 -0700 | [diff] [blame] | 19 | #include <binder/Parcel.h> |
| 20 | #include <binder/TextOutput.h> |
| 21 | #include "android-base/file.h" |
| 22 | #include "android-base/test_utils.h" |
| 23 | |
| 24 | #include <fcntl.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <cstddef> |
| 28 | #include <limits> |
| 29 | |
| 30 | // Fuzzer for the TextOutput class. These were lifted from the existing |
| 31 | // test suite. |
| 32 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 33 | FuzzedDataProvider fdp(data, size); |
| 34 | CapturedStderr cap; |
| 35 | |
| 36 | while (fdp.remaining_bytes() > 1) { |
| 37 | switch (fdp.ConsumeIntegral<uint8_t>() % 3) { |
| 38 | case 0: { |
| 39 | std::string input = fdp.ConsumeBytesAsString( |
| 40 | fdp.ConsumeIntegralInRange<size_t>(0, fdp.remaining_bytes())); |
| 41 | android::aerr << input << android::endl; |
| 42 | break; |
| 43 | } |
| 44 | case 1: { |
| 45 | std::string str = fdp.ConsumeRandomLengthString(fdp.remaining_bytes()); |
| 46 | android::HexDump input(str.c_str(), sizeof(str.c_str())); |
| 47 | android::aerr << input << android::endl; |
| 48 | break; |
| 49 | } |
| 50 | case 2: { |
| 51 | android::TypeCode input(fdp.ConsumeIntegral<uint32_t>()); |
| 52 | android::aerr << input << android::endl; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | cap.Stop(); |
| 57 | |
| 58 | return 0; |
| 59 | } |