1*2d543d20SAndroid Build Coastguard Worker /* 2*2d543d20SAndroid Build Coastguard Worker * Copyright 2020 The Android Open Source Project 3*2d543d20SAndroid Build Coastguard Worker * 4*2d543d20SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*2d543d20SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*2d543d20SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*2d543d20SAndroid Build Coastguard Worker * 8*2d543d20SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*2d543d20SAndroid Build Coastguard Worker * 10*2d543d20SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*2d543d20SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*2d543d20SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*2d543d20SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*2d543d20SAndroid Build Coastguard Worker * limitations under the License. 15*2d543d20SAndroid Build Coastguard Worker */ 16*2d543d20SAndroid Build Coastguard Worker 17*2d543d20SAndroid Build Coastguard Worker #include <fuzzer/FuzzedDataProvider.h> 18*2d543d20SAndroid Build Coastguard Worker #include <stddef.h> 19*2d543d20SAndroid Build Coastguard Worker #include <stdint.h> 20*2d543d20SAndroid Build Coastguard Worker #include <string> 21*2d543d20SAndroid Build Coastguard Worker 22*2d543d20SAndroid Build Coastguard Worker #include <selinux/context.h> 23*2d543d20SAndroid Build Coastguard Worker LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)24*2d543d20SAndroid Build Coastguard Workerextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, [[maybe_unused]] size_t size) { 25*2d543d20SAndroid Build Coastguard Worker FuzzedDataProvider fdp(data, size); 26*2d543d20SAndroid Build Coastguard Worker std::string contextName = fdp.ConsumeRemainingBytesAsString(); 27*2d543d20SAndroid Build Coastguard Worker 28*2d543d20SAndroid Build Coastguard Worker context_t context = context_new(contextName.c_str()); 29*2d543d20SAndroid Build Coastguard Worker // According to docs, this should be safe to call with null pointer 30*2d543d20SAndroid Build Coastguard Worker // (meaning even if previous call fails). 31*2d543d20SAndroid Build Coastguard Worker context_free(context); 32*2d543d20SAndroid Build Coastguard Worker 33*2d543d20SAndroid Build Coastguard Worker return 0; 34*2d543d20SAndroid Build Coastguard Worker } 35