From dcef2b177e04df0ebbe755d7ceee98c874afd242 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 18 Nov 2022 11:15:43 +0800 Subject: [PATCH] add user Signed-off-by: unknown --- test/fuzztest/abilitycontext_fuzzer/BUILD.gn | 2 +- .../abilitycontext_fuzzer.cpp | 314 ++++++++-------- .../abilitycontext_fuzzer.h | 42 +-- .../abilitycontext_fuzzer/corpus/init | 30 +- .../abilitycontext_fuzzer/project.xml | 50 +-- .../abilitymgrrest_fuzzer.cpp | 248 ++++++------- .../abilitymgrrest_fuzzer.h | 42 +-- .../abilitymgrrest_fuzzer/corpus/init | 30 +- .../abilitymgrrest_fuzzer/project.xml | 50 +-- .../abilityrunningrecord_fuzzer/BUILD.gn | 2 +- .../abilityrunningrecord_fuzzer.cpp | 274 +++++++------- .../abilityrunningrecord_fuzzer.h | 42 +-- .../abilityrunningrecord_fuzzer/corpus/init | 30 +- .../abilityrunningrecord_fuzzer/project.xml | 50 +-- test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn | 2 +- .../amsmgrscheduler_fuzzer.cpp | 292 +++++++-------- .../amsmgrscheduler_fuzzer.h | 42 +-- .../amsmgrscheduler_fuzzer/corpus/init | 30 +- .../amsmgrscheduler_fuzzer/project.xml | 50 +-- .../fuzztest/applifecycledeal_fuzzer/BUILD.gn | 2 +- .../applifecycledeal_fuzzer.cpp | 248 ++++++------- .../applifecycledeal_fuzzer.h | 42 +-- .../applifecycledeal_fuzzer/corpus/init | 30 +- .../applifecycledeal_fuzzer/project.xml | 50 +-- .../appmgrrest_fuzzer/appmgrrest_fuzzer.cpp | 336 +++++++++--------- .../appmgrrest_fuzzer/appmgrrest_fuzzer.h | 42 +-- test/fuzztest/appmgrrest_fuzzer/corpus/init | 30 +- test/fuzztest/appmgrrest_fuzzer/project.xml | 50 +-- .../appstateobservermanager_fuzzer.cpp | 222 ++++++------ .../appstateobservermanager_fuzzer.h | 42 +-- .../corpus/init | 30 +- .../project.xml | 50 +-- test/fuzztest/blockamsservice_fuzzer/BUILD.gn | 2 +- .../blockamsservice_fuzzer.cpp | 160 ++++----- .../blockamsservice_fuzzer.h | 42 +-- .../blockamsservice_fuzzer/corpus/init | 30 +- .../blockamsservice_fuzzer/project.xml | 50 +-- .../cancelwantsender_fuzzer.cpp | 174 ++++----- .../cancelwantsender_fuzzer.h | 42 +-- .../cancelwantsender_fuzzer/corpus/init | 30 +- .../cancelwantsender_fuzzer/project.xml | 50 +-- 41 files changed, 1688 insertions(+), 1688 deletions(-) diff --git a/test/fuzztest/abilitycontext_fuzzer/BUILD.gn b/test/fuzztest/abilitycontext_fuzzer/BUILD.gn index 9045bb03ac..cfe1f8ed74 100644 --- a/test/fuzztest/abilitycontext_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitycontext_fuzzer/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. #####################hydra-fuzz################### import("//build/config/features.gni") diff --git a/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.cpp b/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.cpp index 8e1d0f12df..e0860bbeaf 100644 --- a/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.cpp +++ b/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.cpp @@ -1,157 +1,157 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "abilitycontext_fuzzer.h" - -#include -#include - -#include "ability_record.h" -#define private public -#include "ability_context.h" -#undef private -#include "want.h" -#include "parcel.h" -#include "securec.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t OFFSET_ZERO = 24; -constexpr size_t OFFSET_ONE = 16; -constexpr size_t OFFSET_TWO = 8; -constexpr size_t U32_AT_SIZE = 4; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; -} -sptr GetFuzzAbilityToken() -{ - sptr token = nullptr; - - AbilityRequest abilityRequest; - abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; - abilityRequest.abilityInfo.name = "MainAbility"; - abilityRequest.abilityInfo.type = AbilityType::PAGE; - std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - if (abilityRecord) { - token = abilityRecord->GetToken(); - } - - return token; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - AbilityContext abilityContext; - // fuzz for want - Parcel wantParcel; - Want *want = nullptr; - if (wantParcel.WriteBuffer(data, size)) { - want = Want::Unmarshalling(wantParcel); - } - int requestCode = static_cast(GetU32Data(data)); - abilityContext.StartAbility(*want, requestCode); - abilityContext.TerminateAbility(requestCode); - sptr conn = nullptr; - abilityContext.ConnectAbility(*want, conn); - abilityContext.StopAbility(*want); - std::string name(data, size); - int mode = static_cast(GetU32Data(data)); - abilityContext.GetDir(name, mode); - std::string bundleName(data, size); - int flag = static_cast(GetU32Data(data)); - int accountId = static_cast(GetU32Data(data)); - abilityContext.CreateBundleContext(bundleName, flag, accountId); - std::string permission(data, size); - int pid = static_cast(GetU32Data(data)); - int uid = static_cast(GetU32Data(data)); - abilityContext.VerifyPermission(permission, pid, uid); - std::string permissionName(data, size); - std::string des(data, size); - abilityContext.GetPermissionDes(permissionName, des); - std::vector permissions; - std::string fileName(data, size); - abilityContext.DeleteFile(fileName); - std::string deviceId(data, size); - std::string abilityName(data, size); - std::string moduleName(data, size); - abilityContext.SetCallingContext(deviceId, bundleName, abilityName, moduleName); - std::shared_ptr base = nullptr; - abilityContext.AttachBaseContext(base); - std::string type(data, size); - abilityContext.GetExternalFilesDir(type); - std::string url(data, size); - Uri uri = Uri(url); - abilityContext.UnauthUriPermission(permission, uri, uid); - int patternId = static_cast(GetU32Data(data)); - abilityContext.SetPattern(patternId); - BundleInfo bundleInfo; - std::shared_ptr deal = nullptr; - abilityContext.InitResourceManager(bundleInfo, deal); - int resId = static_cast(GetU32Data(data)); - abilityContext.GetString(resId); - abilityContext.GetStringArray(resId); - abilityContext.GetIntArray(resId); - int themeId = static_cast(GetU32Data(data)); - abilityContext.SetTheme(themeId); - abilityContext.GetColor(resId); - int startId = static_cast(GetU32Data(data)); - abilityContext.TerminateAbilityResult(startId); - abilityContext.SetColorMode(mode); - std::vector wants; - abilityContext.StartAbilities(wants); - return (abilityContext.DisconnectAbility(conn) == 0); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "abilitycontext_fuzzer.h" + +#include +#include + +#include "ability_record.h" +#define private public +#include "ability_context.h" +#undef private +#include "want.h" +#include "parcel.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +constexpr size_t U32_AT_SIZE = 4; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; +} +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + AbilityContext abilityContext; + // fuzz for want + Parcel wantParcel; + Want *want = nullptr; + if (wantParcel.WriteBuffer(data, size)) { + want = Want::Unmarshalling(wantParcel); + } + int requestCode = static_cast(GetU32Data(data)); + abilityContext.StartAbility(*want, requestCode); + abilityContext.TerminateAbility(requestCode); + sptr conn = nullptr; + abilityContext.ConnectAbility(*want, conn); + abilityContext.StopAbility(*want); + std::string name(data, size); + int mode = static_cast(GetU32Data(data)); + abilityContext.GetDir(name, mode); + std::string bundleName(data, size); + int flag = static_cast(GetU32Data(data)); + int accountId = static_cast(GetU32Data(data)); + abilityContext.CreateBundleContext(bundleName, flag, accountId); + std::string permission(data, size); + int pid = static_cast(GetU32Data(data)); + int uid = static_cast(GetU32Data(data)); + abilityContext.VerifyPermission(permission, pid, uid); + std::string permissionName(data, size); + std::string des(data, size); + abilityContext.GetPermissionDes(permissionName, des); + std::vector permissions; + std::string fileName(data, size); + abilityContext.DeleteFile(fileName); + std::string deviceId(data, size); + std::string abilityName(data, size); + std::string moduleName(data, size); + abilityContext.SetCallingContext(deviceId, bundleName, abilityName, moduleName); + std::shared_ptr base = nullptr; + abilityContext.AttachBaseContext(base); + std::string type(data, size); + abilityContext.GetExternalFilesDir(type); + std::string url(data, size); + Uri uri = Uri(url); + abilityContext.UnauthUriPermission(permission, uri, uid); + int patternId = static_cast(GetU32Data(data)); + abilityContext.SetPattern(patternId); + BundleInfo bundleInfo; + std::shared_ptr deal = nullptr; + abilityContext.InitResourceManager(bundleInfo, deal); + int resId = static_cast(GetU32Data(data)); + abilityContext.GetString(resId); + abilityContext.GetStringArray(resId); + abilityContext.GetIntArray(resId); + int themeId = static_cast(GetU32Data(data)); + abilityContext.SetTheme(themeId); + abilityContext.GetColor(resId); + int startId = static_cast(GetU32Data(data)); + abilityContext.TerminateAbilityResult(startId); + abilityContext.SetColorMode(mode); + std::vector wants; + abilityContext.StartAbilities(wants); + return (abilityContext.DisconnectAbility(conn) == 0); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.h b/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.h index eda878b48d..5210be4d80 100644 --- a/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.h +++ b/test/fuzztest/abilitycontext_fuzzer/abilitycontext_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCONTEXT_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCONTEXT_FUZZER_H - -#define FUZZ_PROJECT_NAME "abilitycontext_fuzzer" - -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCONTEXT_FUZZER_H +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCONTEXT_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCONTEXT_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilitycontext_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYCONTEXT_FUZZER_H diff --git a/test/fuzztest/abilitycontext_fuzzer/corpus/init b/test/fuzztest/abilitycontext_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100644 --- a/test/fuzztest/abilitycontext_fuzzer/corpus/init +++ b/test/fuzztest/abilitycontext_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/abilitycontext_fuzzer/project.xml b/test/fuzztest/abilitycontext_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100644 --- a/test/fuzztest/abilitycontext_fuzzer/project.xml +++ b/test/fuzztest/abilitycontext_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp b/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp index 4434c08bfc..06da6d573a 100755 --- a/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp +++ b/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.cpp @@ -1,124 +1,124 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "abilitymgrrest_fuzzer.h" - -#include -#include - -#define private public -#include "ability_interceptor.h" -#include "implicit_start_processor.h" -#include "system_dialog_scheduler.h" -#undef private -#include "inner_mission_info.h" -#include "parcel.h" -#include "securec.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -constexpr size_t OFFSET_ZERO = 24; -constexpr size_t OFFSET_ONE = 16; -constexpr size_t OFFSET_TWO = 8; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; -} -sptr GetFuzzAbilityToken() -{ - sptr token = nullptr; - - AbilityRequest abilityRequest; - abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; - abilityRequest.abilityInfo.name = "MainAbility"; - abilityRequest.abilityInfo.type = AbilityType::PAGE; - std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - if (abilityRecord) { - token = abilityRecord->GetToken(); - } - - return token; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - int pid = static_cast(GetU32Data(data)); - std::string bundleName(data, size); - Parcel wantParcel; - Want *want = nullptr; - if (wantParcel.WriteBuffer(data, size)) { - want = Want::Unmarshalling(wantParcel); - } - int32_t userId = static_cast(GetU32Data(data)); - std::shared_ptr systemDialogScheduler = std::make_shared(); - systemDialogScheduler->GetANRDialogWant(static_cast(userId), pid, *want); - std::vector dialogAppInfos; - systemDialogScheduler->GetSelectorParams(dialogAppInfos); - int32_t labelId = static_cast(GetU32Data(data)); - std::string appName(data, size); - systemDialogScheduler->GetAppNameFromResource(labelId, bundleName, userId, appName); - InnerMissionInfo innerMissionInfo; - innerMissionInfo.ToJsonStr(); - std::string jsonStr(data, size); - innerMissionInfo.FromJsonStr(jsonStr); - std::vector info; - innerMissionInfo.Dump(info); - nlohmann::json value; - std::string node(data, size); - JsonType jsonType = JsonType::STRING; - return innerMissionInfo.CheckJsonNode(value, node, jsonType); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "abilitymgrrest_fuzzer.h" + +#include +#include + +#define private public +#include "ability_interceptor.h" +#include "implicit_start_processor.h" +#include "system_dialog_scheduler.h" +#undef private +#include "inner_mission_info.h" +#include "parcel.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; +} +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + int pid = static_cast(GetU32Data(data)); + std::string bundleName(data, size); + Parcel wantParcel; + Want *want = nullptr; + if (wantParcel.WriteBuffer(data, size)) { + want = Want::Unmarshalling(wantParcel); + } + int32_t userId = static_cast(GetU32Data(data)); + std::shared_ptr systemDialogScheduler = std::make_shared(); + systemDialogScheduler->GetANRDialogWant(static_cast(userId), pid, *want); + std::vector dialogAppInfos; + systemDialogScheduler->GetSelectorParams(dialogAppInfos); + int32_t labelId = static_cast(GetU32Data(data)); + std::string appName(data, size); + systemDialogScheduler->GetAppNameFromResource(labelId, bundleName, userId, appName); + InnerMissionInfo innerMissionInfo; + innerMissionInfo.ToJsonStr(); + std::string jsonStr(data, size); + innerMissionInfo.FromJsonStr(jsonStr); + std::vector info; + innerMissionInfo.Dump(info); + nlohmann::json value; + std::string node(data, size); + JsonType jsonType = JsonType::STRING; + return innerMissionInfo.CheckJsonNode(value, node, jsonType); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.h b/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.h index 4c71bf662d..d3b7317645 100755 --- a/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.h +++ b/test/fuzztest/abilitymgrrest_fuzzer/abilitymgrrest_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRREST_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRREST_FUZZER_H - -#define FUZZ_PROJECT_NAME "abilitymgrrest_fuzzer" - -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRREST_FUZZER_H +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRREST_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRREST_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilitymgrrest_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRREST_FUZZER_H diff --git a/test/fuzztest/abilitymgrrest_fuzzer/corpus/init b/test/fuzztest/abilitymgrrest_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100755 --- a/test/fuzztest/abilitymgrrest_fuzzer/corpus/init +++ b/test/fuzztest/abilitymgrrest_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/abilitymgrrest_fuzzer/project.xml b/test/fuzztest/abilitymgrrest_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100755 --- a/test/fuzztest/abilitymgrrest_fuzzer/project.xml +++ b/test/fuzztest/abilitymgrrest_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn b/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn index b30406cca7..1376bdba25 100644 --- a/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. #####################hydra-fuzz################### import("//build/config/features.gni") diff --git a/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.cpp b/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.cpp index 404bcce163..e396ef82ee 100644 --- a/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.cpp +++ b/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.cpp @@ -1,137 +1,137 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "abilityrunningrecord_fuzzer.h" - -#include -#include - -#include "ability_running_record.h" -#include "ability_record.h" -#include "parcel.h" -#include "securec.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -constexpr uint8_t ENABLE = 2; -constexpr size_t OFFSET_ZERO = 24; -constexpr size_t OFFSET_ONE = 16; -constexpr size_t OFFSET_TWO = 8; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; -} -sptr GetFuzzAbilityToken() -{ - sptr token = nullptr; - - AbilityRequest abilityRequest; - abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; - abilityRequest.abilityInfo.name = "MainAbility"; - abilityRequest.abilityInfo.type = AbilityType::PAGE; - std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - if (abilityRecord) { - token = abilityRecord->GetToken(); - } - - return token; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - std::shared_ptr info; - sptr token = GetFuzzAbilityToken(); - AbilityRunningRecord abilityRecord(info, token); - Parcel wantParcel; - std::shared_ptr want = nullptr; - abilityRecord.SetWant(want); - AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_READY; - abilityRecord.SetState(state); - sptr pretoken = GetFuzzAbilityToken(); - abilityRecord.SetPreToken(pretoken); - int32_t visibility = static_cast(GetU32Data(data)); - abilityRecord.SetVisibility(visibility); - int32_t perceptibility = static_cast(GetU32Data(data)); - abilityRecord.SetPerceptibility(perceptibility); - int32_t connectionState = static_cast(GetU32Data(data)); - abilityRecord.SetConnectionState(connectionState); - int64_t eventId = static_cast(GetU32Data(data)); - abilityRecord.SetEventId(eventId); - int32_t ownerUserId = static_cast(GetU32Data(data)); - abilityRecord.SetOwnerUserId(ownerUserId); - bool flag = *data % ENABLE; - abilityRecord.SetIsSingleUser(flag); - bool isFocus = *data % ENABLE; - abilityRecord.UpdateFocusState(isFocus); - abilityRecord.GetName(); - abilityRecord.GetAbilityInfo(); - abilityRecord.GetWant(); - abilityRecord.GetToken(); - abilityRecord.GetState(); - abilityRecord.GetLastLaunchTime(); - abilityRecord.GetPreToken(); - abilityRecord.GetVisibility(); - abilityRecord.GetPerceptibility(); - abilityRecord.GetConnectionState(); - abilityRecord.GetEventId(); - abilityRecord.SetTerminating(); - abilityRecord.IsTerminating(); - abilityRecord.GetOwnerUserId(); - abilityRecord.IsSingleUser(); - abilityRecord.GetFocusFlag(); - return abilityRecord.IsSameState(state); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "abilityrunningrecord_fuzzer.h" + +#include +#include + +#include "ability_running_record.h" +#include "ability_record.h" +#include "parcel.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; +} +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + std::shared_ptr info; + sptr token = GetFuzzAbilityToken(); + AbilityRunningRecord abilityRecord(info, token); + Parcel wantParcel; + std::shared_ptr want = nullptr; + abilityRecord.SetWant(want); + AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_READY; + abilityRecord.SetState(state); + sptr pretoken = GetFuzzAbilityToken(); + abilityRecord.SetPreToken(pretoken); + int32_t visibility = static_cast(GetU32Data(data)); + abilityRecord.SetVisibility(visibility); + int32_t perceptibility = static_cast(GetU32Data(data)); + abilityRecord.SetPerceptibility(perceptibility); + int32_t connectionState = static_cast(GetU32Data(data)); + abilityRecord.SetConnectionState(connectionState); + int64_t eventId = static_cast(GetU32Data(data)); + abilityRecord.SetEventId(eventId); + int32_t ownerUserId = static_cast(GetU32Data(data)); + abilityRecord.SetOwnerUserId(ownerUserId); + bool flag = *data % ENABLE; + abilityRecord.SetIsSingleUser(flag); + bool isFocus = *data % ENABLE; + abilityRecord.UpdateFocusState(isFocus); + abilityRecord.GetName(); + abilityRecord.GetAbilityInfo(); + abilityRecord.GetWant(); + abilityRecord.GetToken(); + abilityRecord.GetState(); + abilityRecord.GetLastLaunchTime(); + abilityRecord.GetPreToken(); + abilityRecord.GetVisibility(); + abilityRecord.GetPerceptibility(); + abilityRecord.GetConnectionState(); + abilityRecord.GetEventId(); + abilityRecord.SetTerminating(); + abilityRecord.IsTerminating(); + abilityRecord.GetOwnerUserId(); + abilityRecord.IsSingleUser(); + abilityRecord.GetFocusFlag(); + return abilityRecord.IsSameState(state); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.h b/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.h index a0faf7a714..30209a2e47 100644 --- a/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.h +++ b/test/fuzztest/abilityrunningrecord_fuzzer/abilityrunningrecord_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYRUNNINGRECORD_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYRUNNINGRECORD_FUZZER_H - -#define FUZZ_PROJECT_NAME "abilityrunningrecord_fuzzer" - -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYRUNNINGRECORD_FUZZER_H +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYRUNNINGRECORD_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYRUNNINGRECORD_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityrunningrecord_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYRUNNINGRECORD_FUZZER_H diff --git a/test/fuzztest/abilityrunningrecord_fuzzer/corpus/init b/test/fuzztest/abilityrunningrecord_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100644 --- a/test/fuzztest/abilityrunningrecord_fuzzer/corpus/init +++ b/test/fuzztest/abilityrunningrecord_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/abilityrunningrecord_fuzzer/project.xml b/test/fuzztest/abilityrunningrecord_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100644 --- a/test/fuzztest/abilityrunningrecord_fuzzer/project.xml +++ b/test/fuzztest/abilityrunningrecord_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn b/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn index 628ff66e64..81562c491a 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn +++ b/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. #####################hydra-fuzz################### import("//build/config/features.gni") diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp index d4610e5537..15b01b6d9f 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp +++ b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp @@ -1,146 +1,146 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "amsmgrscheduler_fuzzer.h" - -#include -#include - -#define private public -#include "ams_mgr_scheduler.h" -#undef private -#include "ability_record.h" -#include "parcel.h" -#include "securec.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -constexpr uint8_t ENABLE = 2; -constexpr size_t OFFSET_ZERO = 24; -constexpr size_t OFFSET_ONE = 16; -constexpr size_t OFFSET_TWO = 8; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; -} -sptr GetFuzzAbilityToken() -{ - sptr token = nullptr; - - AbilityRequest abilityRequest; - abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; - abilityRequest.abilityInfo.name = "MainAbility"; - abilityRequest.abilityInfo.type = AbilityType::PAGE; - std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - if (abilityRecord) { - token = abilityRecord->GetToken(); - } - - return token; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - std::shared_ptr mgrServiceInner; - std::shared_ptr handler; - AmsMgrScheduler amsMgrScheduler(mgrServiceInner, handler); - sptr response; - amsMgrScheduler.RegisterStartSpecifiedAbilityResponse(response); - sptr token = GetFuzzAbilityToken(); - sptr preToken = nullptr; - std::shared_ptr abilityInfoptr; - std::shared_ptr appInfo; - std::shared_ptr wantptr; - amsMgrScheduler.LoadAbility(token, preToken, abilityInfoptr, appInfo, wantptr); - AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_READY; - amsMgrScheduler.UpdateAbilityState(token, state); - AppExecFwk::ExtensionState extensionState = AppExecFwk::ExtensionState::EXTENSION_STATE_READY; - amsMgrScheduler.UpdateExtensionState(token, extensionState); - bool clearMissionFlag = *data % ENABLE; - amsMgrScheduler.TerminateAbility(token, clearMissionFlag); - sptr callback; - amsMgrScheduler.RegisterAppStateCallback(callback); - int32_t visibility = static_cast(GetU32Data(data)); - int32_t perceptibility = static_cast(GetU32Data(data)); - int32_t connectionState = static_cast(GetU32Data(data)); - amsMgrScheduler.AbilityBehaviorAnalysis(token, preToken, visibility, perceptibility, connectionState); - int32_t userId = static_cast(GetU32Data(data)); - amsMgrScheduler.KillProcessesByUserId(userId); - std::string bundleName(data, size); - int accountId = static_cast(GetU32Data(data)); - amsMgrScheduler.KillProcessWithAccount(bundleName, accountId); - amsMgrScheduler.AbilityAttachTimeOut(token); - amsMgrScheduler.PrepareTerminate(token); - amsMgrScheduler.KillApplication(bundleName); - int uid = static_cast(GetU32Data(data)); - amsMgrScheduler.KillApplicationByUid(bundleName, uid); - amsMgrScheduler.KillApplicationSelf(); - AppExecFwk::RunningProcessInfo info; - amsMgrScheduler.GetRunningProcessInfoByToken(token, info); - Parcel wantParcel; - Want *want = nullptr; - if (wantParcel.WriteBuffer(data, size)) { - want = Want::Unmarshalling(wantParcel); - } - AbilityInfo abilityInfo; - amsMgrScheduler.StartSpecifiedAbility(*want, abilityInfo); - int pid = static_cast(GetU32Data(data)); - AppExecFwk::ApplicationInfo application; - bool debug; - amsMgrScheduler.GetApplicationInfoByProcessID(pid, application, debug); - return amsMgrScheduler.IsReady(); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "amsmgrscheduler_fuzzer.h" + +#include +#include + +#define private public +#include "ams_mgr_scheduler.h" +#undef private +#include "ability_record.h" +#include "parcel.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; +} +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + std::shared_ptr mgrServiceInner; + std::shared_ptr handler; + AmsMgrScheduler amsMgrScheduler(mgrServiceInner, handler); + sptr response; + amsMgrScheduler.RegisterStartSpecifiedAbilityResponse(response); + sptr token = GetFuzzAbilityToken(); + sptr preToken = nullptr; + std::shared_ptr abilityInfoptr; + std::shared_ptr appInfo; + std::shared_ptr wantptr; + amsMgrScheduler.LoadAbility(token, preToken, abilityInfoptr, appInfo, wantptr); + AppExecFwk::AbilityState state = AppExecFwk::AbilityState::ABILITY_STATE_READY; + amsMgrScheduler.UpdateAbilityState(token, state); + AppExecFwk::ExtensionState extensionState = AppExecFwk::ExtensionState::EXTENSION_STATE_READY; + amsMgrScheduler.UpdateExtensionState(token, extensionState); + bool clearMissionFlag = *data % ENABLE; + amsMgrScheduler.TerminateAbility(token, clearMissionFlag); + sptr callback; + amsMgrScheduler.RegisterAppStateCallback(callback); + int32_t visibility = static_cast(GetU32Data(data)); + int32_t perceptibility = static_cast(GetU32Data(data)); + int32_t connectionState = static_cast(GetU32Data(data)); + amsMgrScheduler.AbilityBehaviorAnalysis(token, preToken, visibility, perceptibility, connectionState); + int32_t userId = static_cast(GetU32Data(data)); + amsMgrScheduler.KillProcessesByUserId(userId); + std::string bundleName(data, size); + int accountId = static_cast(GetU32Data(data)); + amsMgrScheduler.KillProcessWithAccount(bundleName, accountId); + amsMgrScheduler.AbilityAttachTimeOut(token); + amsMgrScheduler.PrepareTerminate(token); + amsMgrScheduler.KillApplication(bundleName); + int uid = static_cast(GetU32Data(data)); + amsMgrScheduler.KillApplicationByUid(bundleName, uid); + amsMgrScheduler.KillApplicationSelf(); + AppExecFwk::RunningProcessInfo info; + amsMgrScheduler.GetRunningProcessInfoByToken(token, info); + Parcel wantParcel; + Want *want = nullptr; + if (wantParcel.WriteBuffer(data, size)) { + want = Want::Unmarshalling(wantParcel); + } + AbilityInfo abilityInfo; + amsMgrScheduler.StartSpecifiedAbility(*want, abilityInfo); + int pid = static_cast(GetU32Data(data)); + AppExecFwk::ApplicationInfo application; + bool debug; + amsMgrScheduler.GetApplicationInfoByProcessID(pid, application, debug); + return amsMgrScheduler.IsReady(); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.h b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.h index bd1e7fbb84..10fee682f2 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.h +++ b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMGRSCHEDULER_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMGRSCHEDULER_FUZZER_H - -#define FUZZ_PROJECT_NAME "amsmgrscheduler_fuzzer" - -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMGRSCHEDULER_FUZZER_H +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMGRSCHEDULER_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMGRSCHEDULER_FUZZER_H + +#define FUZZ_PROJECT_NAME "amsmgrscheduler_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_AMSMGRSCHEDULER_FUZZER_H diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/corpus/init b/test/fuzztest/amsmgrscheduler_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/corpus/init +++ b/test/fuzztest/amsmgrscheduler_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/project.xml b/test/fuzztest/amsmgrscheduler_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/project.xml +++ b/test/fuzztest/amsmgrscheduler_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn b/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn index c88ee2da3c..8ed3afd1c8 100644 --- a/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn +++ b/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. #####################hydra-fuzz################### import("//build/config/features.gni") diff --git a/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.cpp b/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.cpp index 19aa63e707..9b38091abb 100644 --- a/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.cpp +++ b/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.cpp @@ -1,124 +1,124 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "applifecycledeal_fuzzer.h" - -#include -#include - -#include "app_lifecycle_deal.h" -#include "ability_record.h" -#include "message_parcel.h" -#include "securec.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -constexpr size_t OFFSET_ZERO = 24; -constexpr size_t OFFSET_ONE = 16; -constexpr size_t OFFSET_TWO = 8; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; -} -sptr GetFuzzAbilityToken() -{ - sptr token = nullptr; - - AbilityRequest abilityRequest; - abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; - abilityRequest.abilityInfo.name = "MainAbility"; - abilityRequest.abilityInfo.type = AbilityType::PAGE; - std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - if (abilityRecord) { - token = abilityRecord->GetToken(); - } - - return token; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - AppLifeCycleDeal appLifeCycleDeal; - sptr thread = nullptr; - appLifeCycleDeal.SetApplicationClient(thread); - std::shared_ptr ability = nullptr; - appLifeCycleDeal.LaunchAbility(ability); - AppLaunchData launchData; - Configuration config; - appLifeCycleDeal.LaunchApplication(launchData, config); - HapModuleInfo abilityStage; - appLifeCycleDeal.AddAbilityStage(abilityStage); - int32_t timeLevel = static_cast(GetU32Data(data)); - appLifeCycleDeal.ScheduleTrimMemory(timeLevel); - int32_t level = static_cast(GetU32Data(data)); - appLifeCycleDeal.ScheduleMemoryLevel(level); - sptr token = GetFuzzAbilityToken(); - appLifeCycleDeal.ScheduleCleanAbility(token); - Want want; - std::string bundleName(data, size); - appLifeCycleDeal.ScheduleAcceptWant(want, bundleName); - sptr callback = nullptr; - appLifeCycleDeal.NotifyLoadRepairPatch(bundleName, callback); - appLifeCycleDeal.NotifyHotReloadPage(callback); - appLifeCycleDeal.NotifyUnLoadRepairPatch(bundleName, callback); - appLifeCycleDeal.GetApplicationClient(); - appLifeCycleDeal.LowMemoryWarning(); - appLifeCycleDeal.ScheduleForegroundRunning(); - appLifeCycleDeal.ScheduleBackgroundRunning(); - appLifeCycleDeal.ScheduleProcessSecurityExit(); - appLifeCycleDeal.ScheduleTerminate(); - return (appLifeCycleDeal.UpdateConfiguration(config) == 0); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "applifecycledeal_fuzzer.h" + +#include +#include + +#include "app_lifecycle_deal.h" +#include "ability_record.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; +} +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + AppLifeCycleDeal appLifeCycleDeal; + sptr thread = nullptr; + appLifeCycleDeal.SetApplicationClient(thread); + std::shared_ptr ability = nullptr; + appLifeCycleDeal.LaunchAbility(ability); + AppLaunchData launchData; + Configuration config; + appLifeCycleDeal.LaunchApplication(launchData, config); + HapModuleInfo abilityStage; + appLifeCycleDeal.AddAbilityStage(abilityStage); + int32_t timeLevel = static_cast(GetU32Data(data)); + appLifeCycleDeal.ScheduleTrimMemory(timeLevel); + int32_t level = static_cast(GetU32Data(data)); + appLifeCycleDeal.ScheduleMemoryLevel(level); + sptr token = GetFuzzAbilityToken(); + appLifeCycleDeal.ScheduleCleanAbility(token); + Want want; + std::string bundleName(data, size); + appLifeCycleDeal.ScheduleAcceptWant(want, bundleName); + sptr callback = nullptr; + appLifeCycleDeal.NotifyLoadRepairPatch(bundleName, callback); + appLifeCycleDeal.NotifyHotReloadPage(callback); + appLifeCycleDeal.NotifyUnLoadRepairPatch(bundleName, callback); + appLifeCycleDeal.GetApplicationClient(); + appLifeCycleDeal.LowMemoryWarning(); + appLifeCycleDeal.ScheduleForegroundRunning(); + appLifeCycleDeal.ScheduleBackgroundRunning(); + appLifeCycleDeal.ScheduleProcessSecurityExit(); + appLifeCycleDeal.ScheduleTerminate(); + return (appLifeCycleDeal.UpdateConfiguration(config) == 0); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} diff --git a/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.h b/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.h index 977e3e9e7f..daf3c495d7 100644 --- a/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.h +++ b/test/fuzztest/applifecycledeal_fuzzer/applifecycledeal_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_APPLIFECYCLEDEAL_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_APPLIFECYCLEDEAL_FUZZER_H - -#define FUZZ_PROJECT_NAME "applifecycledeal_fuzzer" - -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_APPLIFECYCLEDEAL_FUZZER_H +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_APPLIFECYCLEDEAL_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_APPLIFECYCLEDEAL_FUZZER_H + +#define FUZZ_PROJECT_NAME "applifecycledeal_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_APPLIFECYCLEDEAL_FUZZER_H diff --git a/test/fuzztest/applifecycledeal_fuzzer/corpus/init b/test/fuzztest/applifecycledeal_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100644 --- a/test/fuzztest/applifecycledeal_fuzzer/corpus/init +++ b/test/fuzztest/applifecycledeal_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/applifecycledeal_fuzzer/project.xml b/test/fuzztest/applifecycledeal_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100644 --- a/test/fuzztest/applifecycledeal_fuzzer/project.xml +++ b/test/fuzztest/applifecycledeal_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp index 52a23d5130..548011c257 100755 --- a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp +++ b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp @@ -1,168 +1,168 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "appmgrrest_fuzzer.h" - -#include -#include - -#include "app_death_recipient.h" -#include "app_mgr_service_event_handler.h" -#include "app_process_manager.h" -#define private public -#include "app_spawn_client.h" -#include "app_spawn_msg_wrapper.h" -#undef private -#include "app_spawn_socket.h" -#include "remote_client_manager.h" -#include "window_focus_changed_listener.h" -#include "ability_record.h" -#include "parcel.h" -#include "securec.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -constexpr uint8_t ENABLE = 2; -constexpr size_t OFFSET_ZERO = 24; -constexpr size_t OFFSET_ONE = 16; -constexpr size_t OFFSET_TWO = 8; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; -} -sptr GetFuzzAbilityToken() -{ - sptr token = nullptr; - - AbilityRequest abilityRequest; - abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; - abilityRequest.abilityInfo.name = "MainAbility"; - abilityRequest.abilityInfo.type = AbilityType::PAGE; - std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - if (abilityRecord) { - token = abilityRecord->GetToken(); - } - - return token; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - sptr appDeathRecipient = new AppDeathRecipient(); - wptr remote; - appDeathRecipient->OnRemoteDied(remote); - std::shared_ptr handler; - appDeathRecipient->SetEventHandler(handler); - std::shared_ptr serviceInner; - appDeathRecipient->SetAppMgrServiceInner(serviceInner); - bool isRenderProcess = *data % ENABLE; - appDeathRecipient->SetIsRenderProcess(isRenderProcess); - AppProcessManager appProcessManager; - std::shared_ptr appTaskInfo; - appProcessManager.RemoveAppFromRecentList(appTaskInfo); - std::string appName(data, size); - std::string processName(data, size); - pid_t pid = static_cast(GetU32Data(data)); - int32_t recordId = static_cast(GetU32Data(data)); - appProcessManager.AddAppToRecentList(appName, processName, pid, recordId); - appProcessManager.PushAppFront(recordId); - appProcessManager.GetAppTaskInfoById(recordId); - std::string bundleName(data, size); - appProcessManager.GetAppTaskInfoByProcessName(appName, bundleName); - appProcessManager.GetRecentAppList(); - appProcessManager.RemoveAppFromRecentListById(recordId); - appProcessManager.ClearRecentAppList(); - AppSpawnClient appSpawnClient; - appSpawnClient.OpenConnection(); - std::shared_ptr socket; - appSpawnClient.SetSocket(socket); - appSpawnClient.PreStartNWebSpawnProcess(); - appSpawnClient.PreStartNWebSpawnProcessImpl(); - AppSpawnStartMsg startMsg; - appSpawnClient.StartProcess(startMsg, pid); - int status = static_cast(GetU32Data(data)); - appSpawnClient.GetRenderProcessTerminationStatus(startMsg, status); - appSpawnClient.QueryConnectionState(); - appSpawnClient.CloseConnection(); - AppSpawnMsgWrapper appSpawnMsgWrapper; - appSpawnMsgWrapper.AssembleMsg(startMsg); - appSpawnMsgWrapper.VerifyMsg(startMsg); - appSpawnMsgWrapper.DumpMsg(); - appSpawnMsgWrapper.FreeMsg(); - AppSpawnSocket appSpawnSocket; - std::shared_ptr clientSocket; - appSpawnSocket.SetClientSocket(clientSocket); - appSpawnSocket.OpenAppSpawnConnection(); - int32_t len = appSpawnMsgWrapper.GetMsgLength(); - appSpawnSocket.WriteMessage(appSpawnMsgWrapper.GetMsgBuf(), len); - appSpawnSocket.ReadMessage(reinterpret_cast(*data), len); - appSpawnSocket.CloseAppSpawnConnection(); - RemoteClientManager remoteClientManager; - sptr bundleManager = nullptr; - remoteClientManager.SetBundleManager(bundleManager); - std::shared_ptr appSpawnClientptr; - remoteClientManager.SetSpawnClient(appSpawnClientptr); - remoteClientManager.GetSpawnClient(); - remoteClientManager.GetBundleManager(); - remoteClientManager.GetNWebSpawnClient(); - std::shared_ptr owner; - WindowFocusChangedListener windowFocusChangedListener(owner, handler); - sptr focusChangeInfo = nullptr; - windowFocusChangedListener.OnFocused(focusChangeInfo); - windowFocusChangedListener.OnUnfocused(focusChangeInfo); - return (appSpawnClient.StartProcessImpl(startMsg, pid) != 0); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "appmgrrest_fuzzer.h" + +#include +#include + +#include "app_death_recipient.h" +#include "app_mgr_service_event_handler.h" +#include "app_process_manager.h" +#define private public +#include "app_spawn_client.h" +#include "app_spawn_msg_wrapper.h" +#undef private +#include "app_spawn_socket.h" +#include "remote_client_manager.h" +#include "window_focus_changed_listener.h" +#include "ability_record.h" +#include "parcel.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; +} +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + sptr appDeathRecipient = new AppDeathRecipient(); + wptr remote; + appDeathRecipient->OnRemoteDied(remote); + std::shared_ptr handler; + appDeathRecipient->SetEventHandler(handler); + std::shared_ptr serviceInner; + appDeathRecipient->SetAppMgrServiceInner(serviceInner); + bool isRenderProcess = *data % ENABLE; + appDeathRecipient->SetIsRenderProcess(isRenderProcess); + AppProcessManager appProcessManager; + std::shared_ptr appTaskInfo; + appProcessManager.RemoveAppFromRecentList(appTaskInfo); + std::string appName(data, size); + std::string processName(data, size); + pid_t pid = static_cast(GetU32Data(data)); + int32_t recordId = static_cast(GetU32Data(data)); + appProcessManager.AddAppToRecentList(appName, processName, pid, recordId); + appProcessManager.PushAppFront(recordId); + appProcessManager.GetAppTaskInfoById(recordId); + std::string bundleName(data, size); + appProcessManager.GetAppTaskInfoByProcessName(appName, bundleName); + appProcessManager.GetRecentAppList(); + appProcessManager.RemoveAppFromRecentListById(recordId); + appProcessManager.ClearRecentAppList(); + AppSpawnClient appSpawnClient; + appSpawnClient.OpenConnection(); + std::shared_ptr socket; + appSpawnClient.SetSocket(socket); + appSpawnClient.PreStartNWebSpawnProcess(); + appSpawnClient.PreStartNWebSpawnProcessImpl(); + AppSpawnStartMsg startMsg; + appSpawnClient.StartProcess(startMsg, pid); + int status = static_cast(GetU32Data(data)); + appSpawnClient.GetRenderProcessTerminationStatus(startMsg, status); + appSpawnClient.QueryConnectionState(); + appSpawnClient.CloseConnection(); + AppSpawnMsgWrapper appSpawnMsgWrapper; + appSpawnMsgWrapper.AssembleMsg(startMsg); + appSpawnMsgWrapper.VerifyMsg(startMsg); + appSpawnMsgWrapper.DumpMsg(); + appSpawnMsgWrapper.FreeMsg(); + AppSpawnSocket appSpawnSocket; + std::shared_ptr clientSocket; + appSpawnSocket.SetClientSocket(clientSocket); + appSpawnSocket.OpenAppSpawnConnection(); + int32_t len = appSpawnMsgWrapper.GetMsgLength(); + appSpawnSocket.WriteMessage(appSpawnMsgWrapper.GetMsgBuf(), len); + appSpawnSocket.ReadMessage(reinterpret_cast(*data), len); + appSpawnSocket.CloseAppSpawnConnection(); + RemoteClientManager remoteClientManager; + sptr bundleManager = nullptr; + remoteClientManager.SetBundleManager(bundleManager); + std::shared_ptr appSpawnClientptr; + remoteClientManager.SetSpawnClient(appSpawnClientptr); + remoteClientManager.GetSpawnClient(); + remoteClientManager.GetBundleManager(); + remoteClientManager.GetNWebSpawnClient(); + std::shared_ptr owner; + WindowFocusChangedListener windowFocusChangedListener(owner, handler); + sptr focusChangeInfo = nullptr; + windowFocusChangedListener.OnFocused(focusChangeInfo); + windowFocusChangedListener.OnUnfocused(focusChangeInfo); + return (appSpawnClient.StartProcessImpl(startMsg, pid) != 0); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.h b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.h index b98514ca03..bae7b13393 100755 --- a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.h +++ b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_APPMGRREST_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_APPMGRREST_FUZZER_H - -#define FUZZ_PROJECT_NAME "appmgrrest_fuzzer" - -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_APPMGRREST_FUZZER_H +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_APPMGRREST_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_APPMGRREST_FUZZER_H + +#define FUZZ_PROJECT_NAME "appmgrrest_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_APPMGRREST_FUZZER_H diff --git a/test/fuzztest/appmgrrest_fuzzer/corpus/init b/test/fuzztest/appmgrrest_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100755 --- a/test/fuzztest/appmgrrest_fuzzer/corpus/init +++ b/test/fuzztest/appmgrrest_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/appmgrrest_fuzzer/project.xml b/test/fuzztest/appmgrrest_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100755 --- a/test/fuzztest/appmgrrest_fuzzer/project.xml +++ b/test/fuzztest/appmgrrest_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.cpp b/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.cpp index 270bf9a9a2..7ebd3e67cd 100755 --- a/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.cpp +++ b/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.cpp @@ -1,111 +1,111 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "appstateobservermanager_fuzzer.h" - -#include -#include - -#define private public -#include "app_state_observer_manager.h" -#undef private -#include "parcel.h" -#include "securec.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -constexpr uint8_t ENABLE = 2; -constexpr size_t OFFSET_ZERO = 24; -constexpr size_t OFFSET_ONE = 16; -constexpr size_t OFFSET_TWO = 8; -} -uint32_t GetU32Data(const char* ptr) -{ - // convert fuzz input data to an integer - return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - std::shared_ptr appStateObserverManager = std::make_shared(); - sptr observer; - std::vector bundleNameList; - appStateObserverManager->RegisterApplicationStateObserver(observer, bundleNameList); - appStateObserverManager->UnregisterApplicationStateObserver(observer); - appStateObserverManager->AddObserverDeathRecipient(observer); - appStateObserverManager->RemoveObserverDeathRecipient(observer); - std::shared_ptr appRecord; - - appStateObserverManager->HandleOnAppProcessCreated(appRecord); - ApplicationState state = ApplicationState::APP_STATE_CREATE; - bool needNotifyApp = *data % ENABLE; - appStateObserverManager->HandleAppStateChanged(appRecord, state, needNotifyApp); - appStateObserverManager->HandleOnAppProcessDied(appRecord); - - std::shared_ptr renderRecord; - appStateObserverManager->HandleOnRenderProcessCreated(renderRecord); - appStateObserverManager->HandleOnRenderProcessDied(renderRecord); - - ProcessData processData; - appStateObserverManager->HandleOnProcessCreated(processData); - appStateObserverManager->HandleOnProcessStateChanged(appRecord); - appStateObserverManager->HandleOnProcessDied(processData); - AbilityStateData abilityStateData; - bool isAbility = *data % ENABLE; - - appStateObserverManager->HandleStateChangedNotifyObserver(abilityStateData, isAbility); - - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "appstateobservermanager_fuzzer.h" + +#include +#include + +#define private public +#include "app_state_observer_manager.h" +#undef private +#include "parcel.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[0] << OFFSET_ZERO) | (ptr[1] << OFFSET_ONE) | (ptr[2] << OFFSET_TWO) | ptr[3]; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + std::shared_ptr appStateObserverManager = std::make_shared(); + sptr observer; + std::vector bundleNameList; + appStateObserverManager->RegisterApplicationStateObserver(observer, bundleNameList); + appStateObserverManager->UnregisterApplicationStateObserver(observer); + appStateObserverManager->AddObserverDeathRecipient(observer); + appStateObserverManager->RemoveObserverDeathRecipient(observer); + std::shared_ptr appRecord; + + appStateObserverManager->HandleOnAppProcessCreated(appRecord); + ApplicationState state = ApplicationState::APP_STATE_CREATE; + bool needNotifyApp = *data % ENABLE; + appStateObserverManager->HandleAppStateChanged(appRecord, state, needNotifyApp); + appStateObserverManager->HandleOnAppProcessDied(appRecord); + + std::shared_ptr renderRecord; + appStateObserverManager->HandleOnRenderProcessCreated(renderRecord); + appStateObserverManager->HandleOnRenderProcessDied(renderRecord); + + ProcessData processData; + appStateObserverManager->HandleOnProcessCreated(processData); + appStateObserverManager->HandleOnProcessStateChanged(appRecord); + appStateObserverManager->HandleOnProcessDied(processData); + AbilityStateData abilityStateData; + bool isAbility = *data % ENABLE; + + appStateObserverManager->HandleStateChangedNotifyObserver(abilityStateData, isAbility); + + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.h b/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.h index 176ddc3210..76e0c9ac7d 100755 --- a/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.h +++ b/test/fuzztest/appstateobservermanager_fuzzer/appstateobservermanager_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_APPSTATEOBSERVERMANAGER_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_APPSTATEOBSERVERMANAGER_FUZZER_H - -#define FUZZ_PROJECT_NAME "appstateobservermanager_fuzzer" - -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_APPSTATEOBSERVERMANAGER_FUZZER_H +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_APPSTATEOBSERVERMANAGER_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_APPSTATEOBSERVERMANAGER_FUZZER_H + +#define FUZZ_PROJECT_NAME "appstateobservermanager_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_APPSTATEOBSERVERMANAGER_FUZZER_H diff --git a/test/fuzztest/appstateobservermanager_fuzzer/corpus/init b/test/fuzztest/appstateobservermanager_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100755 --- a/test/fuzztest/appstateobservermanager_fuzzer/corpus/init +++ b/test/fuzztest/appstateobservermanager_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/appstateobservermanager_fuzzer/project.xml b/test/fuzztest/appstateobservermanager_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100755 --- a/test/fuzztest/appstateobservermanager_fuzzer/project.xml +++ b/test/fuzztest/appstateobservermanager_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/blockamsservice_fuzzer/BUILD.gn b/test/fuzztest/blockamsservice_fuzzer/BUILD.gn index e1f7a186f5..d7850142f0 100644 --- a/test/fuzztest/blockamsservice_fuzzer/BUILD.gn +++ b/test/fuzztest/blockamsservice_fuzzer/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. #####################hydra-fuzz################### import("//build/config/features.gni") diff --git a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp b/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp index 22e808e9b1..397936903a 100644 --- a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp +++ b/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.cpp @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "blockamsservice_fuzzer.h" - -#include -#include - -#include "ability_manager_client.h" -#include "ability_record.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - auto abilitymgr = AbilityManagerClient::GetInstance(); - if (!abilitymgr) { - return false; - } - - if (abilitymgr->BlockAmsService() != 0) { - return false; - } - - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "blockamsservice_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + if (!abilitymgr) { + return false; + } + + if (abilitymgr->BlockAmsService() != 0) { + return false; + } + + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h b/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h index a40199af44..0ecf6721ef 100644 --- a/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h +++ b/test/fuzztest/blockamsservice_fuzzer/blockamsservice_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAMSSERVICE_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAMSSERVICE_FUZZER_H - -#define FUZZ_PROJECT_NAME "blockamsservice_fuzzer" - -#endif +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAMSSERVICE_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_BLOCKAMSSERVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "blockamsservice_fuzzer" + +#endif diff --git a/test/fuzztest/blockamsservice_fuzzer/corpus/init b/test/fuzztest/blockamsservice_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100644 --- a/test/fuzztest/blockamsservice_fuzzer/corpus/init +++ b/test/fuzztest/blockamsservice_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/blockamsservice_fuzzer/project.xml b/test/fuzztest/blockamsservice_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100644 --- a/test/fuzztest/blockamsservice_fuzzer/project.xml +++ b/test/fuzztest/blockamsservice_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.cpp b/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.cpp index c920ec86e0..bc62cf9018 100644 --- a/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.cpp +++ b/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.cpp @@ -1,87 +1,87 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "cancelwantsender_fuzzer.h" - -#include -#include - -#include "ability_manager_client.h" -#include "securec.h" -#include "parcel.h" -#include "sender_info.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace { -constexpr size_t FOO_MAX_LEN = 1024; -constexpr size_t U32_AT_SIZE = 4; -} -bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) -{ - auto abilitymgr = AbilityManagerClient::GetInstance(); - if (!abilitymgr) { - return false; - } - - Parcel parcel; - sptr sender = nullptr; - if (parcel.WriteBuffer(data, size)) { - sender = iface_cast((static_cast(&parcel))->ReadRemoteObject()); - } - if (sender) { - abilitymgr->CancelWantSender(sender); - } - - return true; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - std::cout << "invalid data" << std::endl; - return 0; - } - - /* Validate the length of size */ - if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { - return 0; - } - - char* ch = (char *)malloc(size + 1); - if (ch == nullptr) { - std::cout << "malloc failed." << std::endl; - return 0; - } - - (void)memset_s(ch, size + 1, 0x00, size + 1); - if (memcpy_s(ch, size, data, size) != EOK) { - std::cout << "copy failed." << std::endl; - free(ch); - ch = nullptr; - return 0; - } - - OHOS::DoSomethingInterestingWithMyAPI(ch, size); - free(ch); - ch = nullptr; - return 0; -} - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cancelwantsender_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "securec.h" +#include "parcel.h" +#include "sender_info.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + if (!abilitymgr) { + return false; + } + + Parcel parcel; + sptr sender = nullptr; + if (parcel.WriteBuffer(data, size)) { + sender = iface_cast((static_cast(&parcel))->ReadRemoteObject()); + } + if (sender) { + abilitymgr->CancelWantSender(sender); + } + + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.h b/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.h index f96d57d46e..844b8291f9 100644 --- a/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.h +++ b/test/fuzztest/cancelwantsender_fuzzer/cancelwantsender_fuzzer.h @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_CANCELWANTSENDER_FUZZER_H -#define FUZZTEST_OHOS_ABILITY_RUNTIME_CANCELWANTSENDER_FUZZER_H - -#define FUZZ_PROJECT_NAME "cancelwantsender_fuzzer" - -#endif +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_CANCELWANTSENDER_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_CANCELWANTSENDER_FUZZER_H + +#define FUZZ_PROJECT_NAME "cancelwantsender_fuzzer" + +#endif diff --git a/test/fuzztest/cancelwantsender_fuzzer/corpus/init b/test/fuzztest/cancelwantsender_fuzzer/corpus/init index 6d6bd4a361..8eb5a7d6eb 100644 --- a/test/fuzztest/cancelwantsender_fuzzer/corpus/init +++ b/test/fuzztest/cancelwantsender_fuzzer/corpus/init @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + FUZZ \ No newline at end of file diff --git a/test/fuzztest/cancelwantsender_fuzzer/project.xml b/test/fuzztest/cancelwantsender_fuzzer/project.xml index 1020c7b430..6e8ad2cfde 100644 --- a/test/fuzztest/cancelwantsender_fuzzer/project.xml +++ b/test/fuzztest/cancelwantsender_fuzzer/project.xml @@ -1,25 +1,25 @@ - - - - - - 1000 - - 300 - - 4096 - - + + + + + + 1000 + + 300 + + 4096 + +