• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "initworkspace_fuzzer.h"
17 #include <string>
18 #include <memory>
19 #include "param_trie.h"
20 #include "param_manager.h"
21 #include "securec.h"
22 constexpr int DATA_SIZE = 2;
23 
24 namespace OHOS {
FuzzInitWorkSpace(const uint8_t * data,size_t size)25     bool FuzzInitWorkSpace(const uint8_t* data, size_t size)
26     {
27         constexpr size_t minSize = sizeof(uint32_t) * DATA_SIZE;
28         if (size < minSize) {
29             return false;
30         }
31 
32         uint32_t spaceSize = 0;
33         if (memcpy_s(&spaceSize, sizeof(uint32_t), data, sizeof(uint32_t)) != 0) {
34             return false;
35         }
36         data += sizeof(uint32_t);
37         size -= sizeof(uint32_t);
38 
39         int onlyRead = 0;
40         if (memcpy_s(&onlyRead, sizeof(int), data, sizeof(int)) != 0) {
41             return false;
42         }
43         WorkSpace *workSpace = GetWorkSpace(0);
44 
45         return (InitWorkSpace(workSpace, onlyRead, spaceSize) == 0);
46     }
47 }
48 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)49 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
50 {
51     OHOS::FuzzInitWorkSpace(data, size);
52     return 0;
53 }