blob: 8b4ed702af3e4381de81a84e885ad3eb023b7cb8 [file] [log] [blame]
Corbin Souffrant84f5c0f2020-06-26 00:42:43 -07001/*
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#pragma once
18
19#include <binder/Binder.h>
20#include <binder/Stability.h>
21#include <fuzzer/FuzzedDataProvider.h>
22
23#define STABILITY_MAX_TAG_LENGTH 2048
24static bool marked = false;
25
26/* This is a vector of lambda functions the fuzzer will pull from.
27 * This is done so new functions can be added to the fuzzer easily
28 * without requiring modifications to the main fuzzer file. This also
29 * allows multiple fuzzers to include this file, if functionality is needed.
30 */
31static const std::vector<
32 std::function<void(FuzzedDataProvider*, android::sp<android::IBinder> const&)>>
33 gStabilityOperations = {
34 // markCompilationUnit(IBinder* binder)
35 [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void {
36 if (!marked) {
37 android::internal::Stability::markCompilationUnit(bbinder.get());
38 marked = true;
39 }
40 },
41
42 // markVintf(IBinder* binder)
43 [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void {
44 if (!marked) {
45 android::internal::Stability::markVintf(bbinder.get());
46 marked = true;
47 }
48 },
49
50 // debugLogStability(const std::string& tag, const sp<IBinder>& binder)
51 [](FuzzedDataProvider* fdp, android::sp<android::IBinder> const& bbinder) -> void {
52 std::string tag = fdp->ConsumeRandomLengthString(STABILITY_MAX_TAG_LENGTH);
53 android::internal::Stability::debugLogStability(tag, bbinder);
54 },
55
56 // markVndk(IBinder* binder)
57 [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void {
58 if (!marked) {
59 android::internal::Stability::markVndk(bbinder.get());
60 marked = true;
61 }
62 },
63
64 // requiresVintfDeclaration(const sp<IBinder>& binder)
65 [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void {
66 android::internal::Stability::requiresVintfDeclaration(bbinder);
67 }};