• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "util_fuzzer.h"
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <string>
21 
22 #include "base/json/json_util.h"
23 
24 #include "frameworks/base/memory/ace_type.h"
25 #include "frameworks/bridge/common/utils/source_map.h"
26 
27 namespace OHOS {
28 using namespace OHOS::Ace;
29 using namespace std;
30 constexpr uint32_t u16m = 65535;
31 string appjsmap = "{\"version\":3,"
32                              "\"file\":\"./pages/dfxtest.js\","
33                              "\"mappings\":\";\","
34                              "\"sources\":[],"
35                              "\"names\":[\"_ohos_router_1\",\"router\",\"_ohos_process_1\",\"process\"]}";
36 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)37 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
38 {
39     bool result = false;
40     uint32_t errorPos = 0;
41     string s(reinterpret_cast<const char*>(data), size % u16m);
42     std::vector<std::string> sourceKeyInfo;
43     OHOS::Ace::Framework::RevSourceMap::ExtractKeyInfo(s, sourceKeyInfo);
44     RefPtr<Framework::RevSourceMap> RevSourceMap = AceType::MakeRefPtr<Framework::RevSourceMap>();
45     RevSourceMap->Init(appjsmap);
46     RevSourceMap->GetOriginalNames(s, errorPos);
47     return result;
48 }
49 
50 
51 } // namespace OHOS
52 
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
55 {
56     /* Run your code on data */
57     OHOS::DoSomethingInterestingWithMyAPI(data, size);
58     return 0;
59 }
60