| Dylan Katz | 7168f27 | 2020-07-02 11:51:44 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 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 <memory.h> | 
|  | 18 |  | 
|  | 19 | #include "fuzzer/FuzzedDataProvider.h" | 
|  | 20 | #include "utils/CallStack.h" | 
|  | 21 |  | 
|  | 22 | static constexpr int MAX_STRING_SIZE = 500; | 
|  | 23 | static constexpr int MAX_IGNORE_DEPTH = 200; | 
|  | 24 |  | 
|  | 25 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 
|  | 26 | FuzzedDataProvider dataProvider(data, size); | 
|  | 27 | size_t ignoreDepth = dataProvider.ConsumeIntegralInRange<size_t>(0, MAX_IGNORE_DEPTH); | 
|  | 28 | int logPriority = dataProvider.ConsumeIntegral<int>(); | 
|  | 29 | pid_t tid = dataProvider.ConsumeIntegral<pid_t>(); | 
|  | 30 | std::string logTag = dataProvider.ConsumeRandomLengthString(MAX_STRING_SIZE); | 
|  | 31 | std::string prefix = dataProvider.ConsumeRandomLengthString(MAX_STRING_SIZE); | 
|  | 32 |  | 
|  | 33 | const char* logTagChars = logTag.c_str(); | 
|  | 34 | const char* prefixChars = prefix.c_str(); | 
|  | 35 |  | 
|  | 36 | android::CallStack::CallStackUPtr callStack = android::CallStack::getCurrent(ignoreDepth); | 
|  | 37 | android::CallStack* callstackPtr = callStack.get(); | 
|  | 38 | android::CallStack::logStack(logTagChars, callstackPtr, | 
|  | 39 | static_cast<android_LogPriority>(logPriority)); | 
|  | 40 | android::CallStack::stackToString(prefixChars); | 
|  | 41 |  | 
|  | 42 | callstackPtr->log(logTagChars, static_cast<android_LogPriority>(logPriority), prefixChars); | 
|  | 43 | callstackPtr->clear(); | 
|  | 44 | callstackPtr->getCurrent(ignoreDepth); | 
|  | 45 | callstackPtr->log(logTagChars, static_cast<android_LogPriority>(logPriority), prefixChars); | 
|  | 46 | callstackPtr->update(ignoreDepth, tid); | 
|  | 47 | callstackPtr->log(logTagChars, static_cast<android_LogPriority>(logPriority), prefixChars); | 
|  | 48 |  | 
|  | 49 | return 0; | 
|  | 50 | } |