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 "report_security_info_fuzzer.h"
17 
18 #include <string>
19 
20 #include "securec.h"
21 
22 #include "security_guard_define.h"
23 #include "sg_collect_client.h"
24 
25 #undef private
26 
27 extern "C" int32_t ReportSecurityInfo(const struct EventInfoSt *info);
28 
29 namespace OHOS {
ReportSecurityInfoFuzzTest(const uint8_t * data,size_t size)30 bool ReportSecurityInfoFuzzTest(const uint8_t* data, size_t size)
31 {
32     int64_t eventId = rand() % (size + 1);
33     EventInfoSt info;
34     info.eventId = eventId;
35     std::string version(reinterpret_cast<const char*>(data), size);
36     info.version = version.c_str();
37     uint32_t cpyLen = size >= CONTENT_MAX_LEN ? CONTENT_MAX_LEN - 1: static_cast<uint32_t>(size);
38     (void) memcpy_s(info.content, CONTENT_MAX_LEN, data, cpyLen);
39     info.contentLen = cpyLen;
40     ReportSecurityInfo(&info);
41     return true;
42 }
43 }  // namespace OHOS
44 
45 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
47 {
48     /* Run your code on date */
49     OHOS::ReportSecurityInfoFuzzTest(data, size);
50     return 0;
51 }
52