• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
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 
16 #include "setpastedata_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21 #include "test_server_service.h"
22 namespace OHOS {
DoFuzzTestServerSetPasteData(const uint8_t * data,size_t size)23     bool DoFuzzTestServerSetPasteData(const uint8_t *data, size_t size)
24     {
25         if ((data == nullptr) || (size == 0)) {
26             return false;
27         }
28         int32_t saId = 5502;
29         bool runOnCreate = false;
30         int minRange = 0;
31         int maxRange = 200;
32         auto testServerService = std::make_shared<OHOS::testserver::TestServerService>(saId, runOnCreate);
33         FuzzedDataProvider fdp(data, size);
34         uint32_t code = MIN_TRANSACTION_ID + 1;
35         std::u16string serviceToken = u"OHOS.testserver.ITestServerInterface";
36         MessageParcel dataParcel;
37         MessageParcel replyParcel;
38         MessageOption option;
39         std::vector<uint8_t> buffer = fdp.ConsumeBytes<uint8_t>(fdp.ConsumeIntegralInRange<size_t>(minRange, maxRange));
40         dataParcel.WriteInterfaceToken(serviceToken);
41         dataParcel.WriteBuffer(buffer.data(), buffer.size());
42         int32_t result = testServerService->OnRemoteRequest(code, dataParcel, replyParcel, option);
43         return result == ERR_NONE;
44     }
45 }
46 
47 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49 {
50     /* Run your code on data */
51     OHOS::DoFuzzTestServerSetPasteData(data, size);
52     return 0;
53 }
54