diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 7cb30614f582bc3a2c996dc7960341d0aded7592..7cefe2d87c89970fb78b5a07c39c16db8f4d4a6d 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -384,7 +384,8 @@ int32_t FileShare::CreateShareFile(const vector &uriList, int32_t FileShare::DeleteShareFile(uint32_t tokenId, const vector &uriList) { lock_guard lock(mapMutex_); - string bundleName, currentUid; + string bundleName; + string currentUid; int32_t ret = GetTargetInfo(tokenId, bundleName, currentUid); if (ret != 0) { LOGE("Failed to delete share file %{public}d", -EINVAL); diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index b69a4aaaa19b451c98f0fc0156b12a2c4a45bee0..534cdc16a5ce64980d4fba8c54ce5cbf97fb1654 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,6 +18,5 @@ group("fuzztest") { # deps file "backupsa_fuzzer:BackupSaFuzzTest", "fileshare_fuzzer:FileShareFuzzTest", - "remotefileshare_fuzzer:RemoteFileShareFuzzTest", ] } diff --git a/test/fuzztest/remotefileshare_fuzzer/BUILD.gn b/test/fuzztest/remotefileshare_fuzzer/BUILD.gn deleted file mode 100644 index 87e0bd78ce8007886a1f09d5e2d6d8f6a8543306..0000000000000000000000000000000000000000 --- a/test/fuzztest/remotefileshare_fuzzer/BUILD.gn +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2021-2023 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/test.gni") -import("//foundation/filemanagement/app_file_service/app_file_service.gni") - -##############################fuzztest########################################## -ohos_fuzztest("RemoteFileShareFuzzTest") { - module_out_path = "app_file_service/app_file_service" - fuzz_config_file = - "${app_file_service_path}/test/fuzztest/remotefileshare_fuzzer" - include_dirs = [] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "remotefileshare_fuzzer.cpp" ] - - deps = [ "${third_party_path}/bounds_checking_function:libsec_shared" ] - - external_deps = [ - "file_api:filemgmt_libn", - "hilog:libhilog", - ] - - defines = [ - "LOG_TAG=\"app_file_service\"", - "LOG_DOMAIN=0xD200000", - ] -} - -############################################################################### - diff --git a/test/fuzztest/remotefileshare_fuzzer/corpus/init b/test/fuzztest/remotefileshare_fuzzer/corpus/init deleted file mode 100644 index 8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5..0000000000000000000000000000000000000000 --- a/test/fuzztest/remotefileshare_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,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. - */ - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/remotefileshare_fuzzer/project.xml b/test/fuzztest/remotefileshare_fuzzer/project.xml deleted file mode 100644 index 85e7ef2c1cc6471e288306f6e3dcea5287a78b0e..0000000000000000000000000000000000000000 --- a/test/fuzztest/remotefileshare_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.cpp b/test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.cpp deleted file mode 100644 index c47b367c473b69a2be68d55936ff1b345cd18ad4..0000000000000000000000000000000000000000 --- a/test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.cpp +++ /dev/null @@ -1,193 +0,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 "remotefileshare_fuzzer.h" - -#include -#include -#include -#include -#include -#include - -#include - -#include "securec.h" - -namespace OHOS { -namespace AppFileService { -namespace ModuleRemoteFileShare { -namespace { - constexpr int HMDFS_CID_SIZE = 64; - constexpr unsigned HMDFS_IOC = 0xf2; - const char* SHARE_PATH = "/data/storage/el2/distributedfiles/.share"; -} - -#define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, struct hmdfs_share_control) - -struct hmdfs_share_control { - int src_fd; - char cid[HMDFS_CID_SIZE]; -}; - -bool ShareFilePathIoctlFdAndCidFuzzTest(const uint8_t* data, size_t size) -{ - struct hmdfs_share_control sc; - int32_t ret = 0; - int32_t dirFd; - - if (size == 0) { - return false; - } - - if (access(SHARE_PATH, F_OK) != 0) { - ret = mkdir(SHARE_PATH, S_IRWXU | S_IRWXG | S_IXOTH); - if (ret < 0) { - return false; - } - } - - char realPath[PATH_MAX] = {0}; - if (!realpath(SHARE_PATH, realPath)) { - return false; - } - dirFd = open(realPath, O_RDONLY); - if (dirFd < 0) { - return false; - } - - const char* cid = reinterpret_cast(data); - sc.src_fd = size; - if (memcpy_s(sc.cid, HMDFS_CID_SIZE, cid, size) != 0) { - close(dirFd); - return false; - } - - ret = ioctl(dirFd, HMDFS_IOC_SET_SHARE_PATH, &sc); - if (ret < 0) { - close(dirFd); - return false; - } - - return true; -} - -bool ShareFilePathIoctlCidFuzzTest(const uint8_t* data, size_t size) -{ - struct hmdfs_share_control sc; - int32_t ret = 0; - int32_t dirFd; - int32_t srcFd; - - if (size == 0) { - return false; - } - - if (access(SHARE_PATH, F_OK) != 0) { - ret = mkdir(SHARE_PATH, S_IRWXU | S_IRWXG | S_IXOTH); - if (ret < 0) { - return false; - } - } - - char realPath[PATH_MAX] = {0}; - if (!realpath(SHARE_PATH, realPath)) { - return false; - } - dirFd = open(realPath, O_RDONLY); - if (dirFd < 0) { - return false; - } - - const char* srcPath = "/data/service/el2/100/hmdfs/non_account/data/com.ohos.camera"; - srcFd = open(srcPath, O_RDONLY); - if (srcFd < 0) { - close(dirFd); - return false; - } - sc.src_fd = size; - const char* cid = reinterpret_cast(data); - if (memcpy_s(sc.cid, HMDFS_CID_SIZE, cid, size) != 0) { - close(dirFd); - close(srcFd); - return false; - } - - ret = ioctl(dirFd, HMDFS_IOC_SET_SHARE_PATH, &sc); - if (ret < 0) { - close(dirFd); - close(srcFd); - return false; - } - - close(srcFd); - return true; -} - -bool ShareFilePathIoctlFdFuzzTest(const uint8_t* data, size_t size) -{ - struct hmdfs_share_control sc; - int32_t ret = 0; - int32_t dirFd; - - if (size == 0) { - return false; - } - - if (access(SHARE_PATH, F_OK) != 0) { - ret = mkdir(SHARE_PATH, S_IRWXU | S_IRWXG | S_IXOTH); - if (ret < 0) { - return false; - } - } - - char realPath[PATH_MAX] = {0}; - if (!realpath(SHARE_PATH, realPath)) { - return false; - } - - dirFd = open(realPath, O_RDONLY); - if (dirFd < 0) { - return false; - } - - const char* cid = "remoteShareFileFuzzTestCidxxx"; - if (memcpy_s(sc.cid, HMDFS_CID_SIZE, cid, strlen(cid)) != 0) { - close(dirFd); - return false; - } - sc.src_fd = size; - - ret = ioctl(dirFd, HMDFS_IOC_SET_SHARE_PATH, &sc); - if (ret < 0) { - close(dirFd); - return false; - } - - return true; -} -} // namespace ModuleRemoteFileShare -} // namespace AppFileService -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::AppFileService::ModuleRemoteFileShare::ShareFilePathIoctlFdFuzzTest(data, size); - OHOS::AppFileService::ModuleRemoteFileShare::ShareFilePathIoctlCidFuzzTest(data, size); - OHOS::AppFileService::ModuleRemoteFileShare::ShareFilePathIoctlFdAndCidFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.h b/test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.h deleted file mode 100644 index 433624e715733b7830d8862325e1c4bd3848c6b9..0000000000000000000000000000000000000000 --- a/test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2021 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 REMOTEFILESHARE_FUZZER_H -#define REMOTEFILESHARE_FUZZER_H - -#define FUZZ_PROJECT_NAME "remotefileshare_fuzzer" - -#endif \ No newline at end of file diff --git a/test/unittest/remote_file_share/BUILD.gn b/test/unittest/remote_file_share/BUILD.gn index f3e9d436c1b43e213316417041be5e084bb765d4..67ca689cdd71f65eda1d6662fae2e3d502a9668e 100644 --- a/test/unittest/remote_file_share/BUILD.gn +++ b/test/unittest/remote_file_share/BUILD.gn @@ -16,8 +16,6 @@ import("//foundation/filemanagement/app_file_service/app_file_service.gni") ohos_unittest("remote_file_share_test") { module_out_path = "filemanagement/app_file_service" - fuzz_config_file = - "${app_file_service_path}/test/fuzztest/remotefileshare_fuzzer" resource_config_file = "../resource/ohos_test.xml" sources = [ "remote_file_share_test.cpp" ]