1 /*
2 * Copyright (c) 2024 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 #include "fileaccessextconnection_fuzzer.h"
16
17 #include <cstring>
18 #include <memory>
19
20 #include "hilog_wrapper.h"
21 #include "file_access_ext_connection.h"
22
23 namespace OHOS {
24 using namespace std;
25 using namespace FileAccessFwk;
26
OnAbilityConnectDoneFuzzTest(shared_ptr<FileAccessExtConnection> conn)27 bool OnAbilityConnectDoneFuzzTest(shared_ptr<FileAccessExtConnection> conn)
28 {
29 AppExecFwk::ElementName element;
30 sptr<IRemoteObject> remoteObject = nullptr;
31 conn->OnAbilityConnectDone(element, remoteObject, 0);
32 return true;
33 }
34
OnAbilityDisconnectDoneFuzzTest(shared_ptr<FileAccessExtConnection> conn)35 bool OnAbilityDisconnectDoneFuzzTest(shared_ptr<FileAccessExtConnection> conn)
36 {
37 AppExecFwk::ElementName element;
38 conn->OnAbilityDisconnectDone(element, 0);
39 return true;
40 }
41
IsExtAbilityConnectedFuzzTest(shared_ptr<FileAccessExtConnection> conn)42 bool IsExtAbilityConnectedFuzzTest(shared_ptr<FileAccessExtConnection> conn)
43 {
44 conn->IsExtAbilityConnected();
45 return true;
46 }
47
GetFileExtProxyFuzzTest(shared_ptr<FileAccessExtConnection> conn)48 bool GetFileExtProxyFuzzTest(shared_ptr<FileAccessExtConnection> conn)
49 {
50 conn->GetFileExtProxy();
51 return true;
52 }
53
ConnectFileExtAbility(shared_ptr<FileAccessExtConnection> conn)54 bool ConnectFileExtAbility(shared_ptr<FileAccessExtConnection> conn)
55 {
56 AAFwk::Want want;
57 sptr<IRemoteObject> remoteObject = nullptr;
58 conn->ConnectFileExtAbility(want, remoteObject);
59 return true;
60 }
61
DisconnectFileExtAbility(shared_ptr<FileAccessExtConnection> conn)62 bool DisconnectFileExtAbility(shared_ptr<FileAccessExtConnection> conn)
63 {
64 conn->DisconnectFileExtAbility();
65 return true;
66 }
67
68
69 } // namespace OHOS
70
71 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)72 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
73 {
74 auto conn = std::make_shared<OHOS::FileAccessFwk::FileAccessExtConnection>();
75 if (conn == nullptr) {
76 return 0;
77 }
78
79 OHOS::OnAbilityConnectDoneFuzzTest(conn);
80 OHOS::OnAbilityDisconnectDoneFuzzTest(conn);
81 OHOS::IsExtAbilityConnectedFuzzTest(conn);
82 OHOS::GetFileExtProxyFuzzTest(conn);
83 OHOS::ConnectFileExtAbility(conn);
84 OHOS::DisconnectFileExtAbility(conn);
85
86 return 0;
87 }
88