• 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 "setdragwindowvisible_fuzzer.h"
17 
18 #include "securec.h"
19 
20 #include "devicestatus_define.h"
21 #include "fi_log.h"
22 #include "interaction_manager.h"
23 
24 namespace OHOS {
25 namespace Msdp {
26 namespace DeviceStatus {
27 namespace {
28 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "SetDragWindowVisibleFuzzTest" };
29 constexpr int32_t NUM_TWO { 2 };
30 } // namespace
31 
32 template<class T>
GetObject(const uint8_t * data,size_t size,T & object)33 void GetObject(const uint8_t *data, size_t size, T &object)
34 {
35     size_t objectSize = sizeof(object);
36     if (objectSize > size) {
37         return;
38     }
39     errno_t ret = memcpy_s(&object, objectSize, data, objectSize);
40     if (ret != EOK) {
41         return;
42     }
43 }
44 
SetDragWindowVisibleFuzzTest(const uint8_t * data,size_t size)45 void SetDragWindowVisibleFuzzTest(const uint8_t* data, size_t size)
46 {
47     CALL_DEBUG_ENTER;
48     bool bWindowVisible = false;
49     int32_t num = 0;
50     GetObject<int32_t>(data, size, num);
51     if ((num % NUM_TWO) == 1) {
52         bWindowVisible = true;
53     }
54     int32_t ret = InteractionManager::GetInstance()->SetDragWindowVisible(bWindowVisible);
55     FI_HILOGD("ret:%{public}d", ret);
56 }
57 } // namespace DeviceStatus
58 } // namespace Msdp
59 } // namespace OHOS
60 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63     if (data == nullptr) {
64         return 0;
65     }
66     if (size < sizeof(int32_t)) {
67         return 0;
68     }
69     OHOS::Msdp::DeviceStatus::SetDragWindowVisibleFuzzTest(data, size);
70     return 0;
71 }