diff --git a/bundle.json b/bundle.json
index 6186a794cbe963a528c773ff3fbbb45b1461044c..b940daa1fc984537062819f62eddbcef24b8cfa7 100755
--- a/bundle.json
+++ b/bundle.json
@@ -78,7 +78,8 @@
],
"test": [
"//foundation/distributedschedule/samgr/services/samgr/native/test:unittest",
- "//foundation/distributedschedule/samgr/services/common/test:unittest"
+ "//foundation/distributedschedule/samgr/services/common/test:unittest",
+ "//foundation/distributedschedule/samgr/test/fuzztest/system_ability_manager_fuzzer:fuzztest"
]
}
}
diff --git a/test/fuzztest/system_ability_manager_fuzzer/BUILD.gn b/test/fuzztest/system_ability_manager_fuzzer/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..360106ef837f028b5054e94a06a0d0a126626bae
--- /dev/null
+++ b/test/fuzztest/system_ability_manager_fuzzer/BUILD.gn
@@ -0,0 +1,66 @@
+# 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.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/ohos.gni")
+import("//build/test.gni")
+module_output_path = "samgr/fuzztest"
+samgr_dir = "//foundation/distributedschedule/samgr"
+samgr_services_dir = "${samgr_dir}/services/samgr/native"
+
+##############################fuzztest##########################################
+ohos_fuzztest("SystemAbilityFuzz") {
+ module_out_path = module_output_path
+
+ configs = [
+ "${samgr_dir}/interfaces/innerkits/lsamgr:config_samgr",
+ "${samgr_dir}/services/samgr/native:sam_config",
+ ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [
+ "${samgr_dir}/utils/native/source/tools.cpp",
+ "${samgr_services_dir}/source/system_ability_manager.cpp",
+ "${samgr_services_dir}/source/system_ability_manager_stub.cpp",
+ "system_ability_manager_fuzzer.cpp",
+ ]
+ deps = []
+
+ external_deps = [
+ "access_token:libaccesstoken_sdk",
+ "eventhandler:libeventhandler",
+ "hiviewdfx_hilog_native:libhilog",
+ "init:libbegetutil",
+ "ipc:ipc_core",
+ "ipc:libdbinder",
+ "samgr_standard:samgr_proxy",
+ "utils_base:utils",
+ ]
+ public_deps = [ "//third_party/libxml2:libxml2" ]
+}
+
+group("fuzztest") {
+ testonly = true
+ deps = []
+
+ deps += [
+ # deps file
+ ":SystemAbilityFuzz",
+ ]
+}
diff --git a/test/fuzztest/system_ability_manager_fuzzer/project.xml b/test/fuzztest/system_ability_manager_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec
--- /dev/null
+++ b/test/fuzztest/system_ability_manager_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/system_ability_manager_fuzzer/system_ability_manager_fuzzer.cpp b/test/fuzztest/system_ability_manager_fuzzer/system_ability_manager_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c05579eccd4f5696c1ef3c56779f8d7f0d8e44e3
--- /dev/null
+++ b/test/fuzztest/system_ability_manager_fuzzer/system_ability_manager_fuzzer.cpp
@@ -0,0 +1,70 @@
+/*
+ * 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 "system_ability_manager_fuzzer.h"
+
+#include "if_system_ability_manager.h"
+#include "system_ability_manager.h"
+
+#include
+#include
+#include
+#include
+#include
+
+namespace OHOS {
+namespace Samgr {
+namespace {
+ constexpr size_t THRESHOLD = 10;
+ constexpr uint8_t MAX_CALL_TRANSACTION = 64;
+ constexpr int32_t OFFSET = 4;
+ const std::u16string SAMGR_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
+}
+
+uint32_t Convert2Uint32(const uint8_t* ptr)
+{
+ if (ptr == nullptr) {
+ return 0;
+ }
+ return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]);
+}
+
+void FuzzSystemAbilityManager(const uint8_t* rawData, size_t size)
+{
+ uint32_t code = Convert2Uint32(rawData);
+ rawData = rawData + OFFSET;
+ size = size - OFFSET;
+ MessageParcel data;
+ data.WriteInterfaceToken(SAMGR_INTERFACE_TOKEN);
+ data.WriteBuffer(rawData, size);
+ data.RewindRead(0);
+ MessageParcel reply;
+ MessageOption option;
+ SystemAbilityManager::GetInstance()->OnRemoteRequest(code % MAX_CALL_TRANSACTION, data, reply, option);
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ if (size < OHOS::Samgr::THRESHOLD) {
+ return -1;
+ }
+
+ OHOS::Samgr::FuzzSystemAbilityManager(data, size);
+ return 0;
+}
+
diff --git a/test/fuzztest/system_ability_manager_fuzzer/system_ability_manager_fuzzer.h b/test/fuzztest/system_ability_manager_fuzzer/system_ability_manager_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..a96e758f6ccc356fa78f13f355d1784fa50f775f
--- /dev/null
+++ b/test/fuzztest/system_ability_manager_fuzzer/system_ability_manager_fuzzer.h
@@ -0,0 +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 SAMGR_TEST_FUZZTEST_SYSTEM_ABILITY_MANAGER_FUZZER_H
+#define SAMGR_TEST_FUZZTEST_SYSTEM_ABILITY_MANAGER_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "system_ability_manager_fuzzer"
+
+#endif
\ No newline at end of file