From e76abb01909c6751fb3891218632f2a072b62fcc Mon Sep 17 00:00:00 2001 From: lvyuanyuan Date: Thu, 22 Feb 2024 10:06:38 +0800 Subject: [PATCH] fixed 54e1af2 from https://gitee.com/lvyuanyuan0712/filemanagement_app_file_service_5/pulls/675 cleancode fix Signed-off-by: lvyuanyuan Change-Id: Ie070e4e47d29be99d0450ad3803a5994954a9fb1 --- .../native/file_share/src/file_share.cpp | 3 +- test/fuzztest/BUILD.gn | 1 - test/fuzztest/remotefileshare_fuzzer/BUILD.gn | 47 ----- .../remotefileshare_fuzzer/corpus/init | 16 -- .../remotefileshare_fuzzer/project.xml | 25 --- .../remotefileshare_fuzzer.cpp | 193 ------------------ .../remotefileshare_fuzzer.h | 21 -- test/unittest/remote_file_share/BUILD.gn | 2 - 8 files changed, 2 insertions(+), 306 deletions(-) delete mode 100644 test/fuzztest/remotefileshare_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/remotefileshare_fuzzer/corpus/init delete mode 100644 test/fuzztest/remotefileshare_fuzzer/project.xml delete mode 100644 test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.cpp delete mode 100644 test/fuzztest/remotefileshare_fuzzer/remotefileshare_fuzzer.h diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 7cb30614f..7cefe2d87 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 b69a4aaaa..534cdc16a 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 87e0bd78c..000000000 --- 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 8eb5a7d6e..000000000 --- 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 85e7ef2c1..000000000 --- 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 c47b367c4..000000000 --- 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 433624e71..000000000 --- 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 f3e9d436c..67ca689cd 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" ] -- Gitee