• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <fuzzer/FuzzedDataProvider.h>
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "message_parcel.h"
22 #include "wallpaper_service.h"
23 #include "wallpaperstub_fuzzer.h"
24 
25 using namespace OHOS::WallpaperMgrService;
26 namespace OHOS {
27 const std::u16string WALLPAPERSERVICES_INTERFACE_TOKEN = u"OHOS.WallpaperMgrService.IWallpaperService";
28 
FuzzTestRemoteRequest(FuzzedDataProvider & provider)29 void FuzzTestRemoteRequest(FuzzedDataProvider &provider)
30 {
31     MessageParcel data;
32     data.WriteInterfaceToken(WALLPAPERSERVICES_INTERFACE_TOKEN);
33     std::vector<uint8_t> remaining_data = provider.ConsumeRemainingBytes<uint8_t>();
34     data.WriteBuffer(static_cast<void *>(remaining_data.data()), remaining_data.size());
35     data.RewindRead(0);
36     MessageParcel reply;
37     MessageOption option;
38     std::shared_ptr<WallpaperService> wallpaperService = std::make_shared<WallpaperService>();
39     uint32_t code = provider.ConsumeIntegral<uint32_t>();
40     wallpaperService->OnRemoteRequest(code, data, reply, option);
41 }
42 } // namespace OHOS
43 
44 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)45 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
46 {
47     FuzzedDataProvider provider(data, size);
48     OHOS::FuzzTestRemoteRequest(provider);
49     return 0;
50 }