From 59eed1b462ced8801639882d03367dc17ac4e509 Mon Sep 17 00:00:00 2001 From: 18802956297 Date: Thu, 26 May 2022 15:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=8F=90=E4=BA=A4fuzz?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hc_node/hc_enable_fuzzer/BUILD.gn | 43 ++++++++ hc_node/hc_enable_fuzzer/corpus/init | 13 +++ hc_node/hc_enable_fuzzer/fs_fuzzer.cpp | 58 +++++++++++ hc_node/hc_enable_fuzzer/fs_fuzzer.h | 23 +++++ hc_node/hc_enable_fuzzer/project.xml | 25 +++++ .../hc_hot_data_lower_limit_fuzzer/BUILD.gn | 48 +++++++++ .../corpus/init | 13 +++ .../hot_data_lower_limit_fuzzer.cpp | 97 +++++++++++++++++++ .../hot_data_lower_limit_fuzzer.h | 23 +++++ .../project.xml | 25 +++++ hc_node/hc_hot_data_waterline_fuzzer/BUILD.gn | 48 +++++++++ .../hc_hot_data_waterline_fuzzer/corpus/init | 13 +++ .../hot_data_waterline_fuzzer.cpp | 97 +++++++++++++++++++ .../hot_data_waterline_fuzzer.h | 23 +++++ .../hc_hot_data_waterline_fuzzer/project.xml | 25 +++++ hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn | 48 +++++++++ .../hchotnodelowerlimit_fuzzer/corpus/init | 13 +++ .../hchotnodelowerlimit_fuzzer.cpp | 59 +++++++++++ .../hchotnodelowerlimit_fuzzer.h | 23 +++++ .../hchotnodelowerlimit_fuzzer/project.xml | 25 +++++ hc_node/hchotnodewaterline_fuzzer/BUILD.gn | 48 +++++++++ hc_node/hchotnodewaterline_fuzzer/corpus/init | 13 +++ .../hchotnodewaterline_fuzzer.cpp | 57 +++++++++++ .../hchotnodewaterline_fuzzer.h | 23 +++++ hc_node/hchotnodewaterline_fuzzer/project.xml | 25 +++++ hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn | 48 +++++++++ .../hcwarmnodelowerlimit_fuzzer/corpus/init | 13 +++ .../hcwarmnodelowerlimit_fuzzer.cpp | 53 ++++++++++ .../hcwarmnodelowerlimit_fuzzer.h | 23 +++++ .../hcwarmnodelowerlimit_fuzzer/project.xml | 25 +++++ hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn | 48 +++++++++ .../hcwarmnodewaterline_fuzzer/corpus/init | 13 +++ .../hcwarmnodewaterline_fuzzer.cpp | 53 ++++++++++ .../hcwarmnodewaterline_fuzzer.h | 23 +++++ .../hcwarmnodewaterline_fuzzer/project.xml | 25 +++++ hc_node/warmdatalowerlimit_fuzzer/BUILD.gn | 47 +++++++++ hc_node/warmdatalowerlimit_fuzzer/corpus/init | 13 +++ hc_node/warmdatalowerlimit_fuzzer/project.xml | 25 +++++ .../warmdatalowerlimit_fuzzer.cpp | 43 ++++++++ .../warmdatalowerlimit_fuzzer.h | 32 ++++++ hc_node/warmdatawaterline_fuzzer/BUILD.gn | 47 +++++++++ hc_node/warmdatawaterline_fuzzer/corpus/init | 13 +++ hc_node/warmdatawaterline_fuzzer/project.xml | 25 +++++ .../warmdatawaterline_fuzzer.cpp | 43 ++++++++ .../warmdatawaterline_fuzzer.h | 32 ++++++ ioctl/getftokenid_fuzzer/BUILD.gn | 51 ++++++++++ .../accesstokenid_getftokenid.cpp | 51 ++++++++++ .../accesstokenid_getftokenid.h | 40 ++++++++ ioctl/getftokenid_fuzzer/corpus/init | 14 +++ .../getftokenid_fuzzer/getftokenid_fuzzer.cpp | 55 +++++++++++ ioctl/getftokenid_fuzzer/getftokenid_fuzzer.h | 6 ++ ioctl/getftokenid_fuzzer/project.xml | 25 +++++ ioctl/gettokenidcmdcorrect_fuzzer/BUILD.gn | 51 ++++++++++ .../accesstokenid.cpp | 75 ++++++++++++++ .../accesstokenid.h | 30 ++++++ ioctl/gettokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../gettokenidcmdcorrect_fuzzer.cpp | 57 +++++++++++ .../gettokenidcmdcorrect_fuzzer.h | 6 ++ ioctl/gettokenidcmdcorrect_fuzzer/project.xml | 25 +++++ ioctl/gettokenidcmderror_fuzzer/BUILD.gn | 51 ++++++++++ .../accesstokenid.cpp | 76 +++++++++++++++ .../gettokenidcmderror_fuzzer/accesstokenid.h | 30 ++++++ ioctl/gettokenidcmderror_fuzzer/corpus/init | 14 +++ .../gettokenidcmderror_fuzzer.cpp | 54 +++++++++++ .../gettokenidcmderror_fuzzer.h | 6 ++ ioctl/gettokenidcmderror_fuzzer/project.xml | 25 +++++ ioctl/setftokenid_fuzzer/BUILD.gn | 51 ++++++++++ .../accesstokenid_setftokenid.cpp | 50 ++++++++++ .../accesstokenid_setftokenid.h | 40 ++++++++ ioctl/setftokenid_fuzzer/corpus/init | 14 +++ ioctl/setftokenid_fuzzer/project.xml | 25 +++++ .../setftokenid_fuzzer/setftokenid_fuzzer.cpp | 55 +++++++++++ ioctl/setftokenid_fuzzer/setftokenid_fuzzer.h | 6 ++ ioctl/settokenidcmdcorrect_fuzzer/BUILD.gn | 51 ++++++++++ .../accesstokenid.cpp | 75 ++++++++++++++ .../accesstokenid.h | 29 ++++++ ioctl/settokenidcmdcorrect_fuzzer/corpus/init | 14 +++ ioctl/settokenidcmdcorrect_fuzzer/project.xml | 25 +++++ .../settokenidcmdcorrect_fuzzer.cpp | 57 +++++++++++ .../settokenidcmdcorrect_fuzzer.h | 6 ++ ioctl/settokenidcmderror_fuzzer/BUILD.gn | 51 ++++++++++ .../accesstokenid.cpp | 75 ++++++++++++++ .../settokenidcmderror_fuzzer/accesstokenid.h | 29 ++++++ ioctl/settokenidcmderror_fuzzer/corpus/init | 14 +++ ioctl/settokenidcmderror_fuzzer/project.xml | 25 +++++ .../settokenidcmderror_fuzzer.cpp | 54 +++++++++++ .../settokenidcmderror_fuzzer.h | 6 ++ 87 files changed, 3060 insertions(+) create mode 100644 hc_node/hc_enable_fuzzer/BUILD.gn create mode 100644 hc_node/hc_enable_fuzzer/corpus/init create mode 100644 hc_node/hc_enable_fuzzer/fs_fuzzer.cpp create mode 100644 hc_node/hc_enable_fuzzer/fs_fuzzer.h create mode 100644 hc_node/hc_enable_fuzzer/project.xml create mode 100644 hc_node/hc_hot_data_lower_limit_fuzzer/BUILD.gn create mode 100644 hc_node/hc_hot_data_lower_limit_fuzzer/corpus/init create mode 100644 hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.cpp create mode 100644 hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.h create mode 100644 hc_node/hc_hot_data_lower_limit_fuzzer/project.xml create mode 100644 hc_node/hc_hot_data_waterline_fuzzer/BUILD.gn create mode 100644 hc_node/hc_hot_data_waterline_fuzzer/corpus/init create mode 100644 hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.cpp create mode 100644 hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.h create mode 100644 hc_node/hc_hot_data_waterline_fuzzer/project.xml create mode 100644 hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn create mode 100644 hc_node/hchotnodelowerlimit_fuzzer/corpus/init create mode 100644 hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp create mode 100644 hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.h create mode 100644 hc_node/hchotnodelowerlimit_fuzzer/project.xml create mode 100644 hc_node/hchotnodewaterline_fuzzer/BUILD.gn create mode 100644 hc_node/hchotnodewaterline_fuzzer/corpus/init create mode 100644 hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp create mode 100644 hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.h create mode 100644 hc_node/hchotnodewaterline_fuzzer/project.xml create mode 100644 hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn create mode 100644 hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init create mode 100644 hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp create mode 100644 hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.h create mode 100644 hc_node/hcwarmnodelowerlimit_fuzzer/project.xml create mode 100644 hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn create mode 100644 hc_node/hcwarmnodewaterline_fuzzer/corpus/init create mode 100644 hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp create mode 100644 hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.h create mode 100644 hc_node/hcwarmnodewaterline_fuzzer/project.xml create mode 100644 hc_node/warmdatalowerlimit_fuzzer/BUILD.gn create mode 100644 hc_node/warmdatalowerlimit_fuzzer/corpus/init create mode 100644 hc_node/warmdatalowerlimit_fuzzer/project.xml create mode 100644 hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.cpp create mode 100644 hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.h create mode 100644 hc_node/warmdatawaterline_fuzzer/BUILD.gn create mode 100644 hc_node/warmdatawaterline_fuzzer/corpus/init create mode 100644 hc_node/warmdatawaterline_fuzzer/project.xml create mode 100644 hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.cpp create mode 100644 hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.h create mode 100644 ioctl/getftokenid_fuzzer/BUILD.gn create mode 100644 ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.cpp create mode 100644 ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.h create mode 100644 ioctl/getftokenid_fuzzer/corpus/init create mode 100644 ioctl/getftokenid_fuzzer/getftokenid_fuzzer.cpp create mode 100644 ioctl/getftokenid_fuzzer/getftokenid_fuzzer.h create mode 100644 ioctl/getftokenid_fuzzer/project.xml create mode 100644 ioctl/gettokenidcmdcorrect_fuzzer/BUILD.gn create mode 100644 ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.cpp create mode 100644 ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.h create mode 100644 ioctl/gettokenidcmdcorrect_fuzzer/corpus/init create mode 100644 ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp create mode 100644 ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h create mode 100644 ioctl/gettokenidcmdcorrect_fuzzer/project.xml create mode 100644 ioctl/gettokenidcmderror_fuzzer/BUILD.gn create mode 100644 ioctl/gettokenidcmderror_fuzzer/accesstokenid.cpp create mode 100644 ioctl/gettokenidcmderror_fuzzer/accesstokenid.h create mode 100644 ioctl/gettokenidcmderror_fuzzer/corpus/init create mode 100644 ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp create mode 100644 ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h create mode 100644 ioctl/gettokenidcmderror_fuzzer/project.xml create mode 100644 ioctl/setftokenid_fuzzer/BUILD.gn create mode 100644 ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.cpp create mode 100644 ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.h create mode 100644 ioctl/setftokenid_fuzzer/corpus/init create mode 100644 ioctl/setftokenid_fuzzer/project.xml create mode 100644 ioctl/setftokenid_fuzzer/setftokenid_fuzzer.cpp create mode 100644 ioctl/setftokenid_fuzzer/setftokenid_fuzzer.h create mode 100644 ioctl/settokenidcmdcorrect_fuzzer/BUILD.gn create mode 100644 ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.cpp create mode 100644 ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.h create mode 100644 ioctl/settokenidcmdcorrect_fuzzer/corpus/init create mode 100644 ioctl/settokenidcmdcorrect_fuzzer/project.xml create mode 100644 ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp create mode 100644 ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h create mode 100644 ioctl/settokenidcmderror_fuzzer/BUILD.gn create mode 100644 ioctl/settokenidcmderror_fuzzer/accesstokenid.cpp create mode 100644 ioctl/settokenidcmderror_fuzzer/accesstokenid.h create mode 100644 ioctl/settokenidcmderror_fuzzer/corpus/init create mode 100644 ioctl/settokenidcmderror_fuzzer/project.xml create mode 100644 ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp create mode 100644 ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h diff --git a/hc_node/hc_enable_fuzzer/BUILD.gn b/hc_node/hc_enable_fuzzer/BUILD.gn new file mode 100644 index 0000000..2d69b72 --- /dev/null +++ b/hc_node/hc_enable_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +##############################FsFuzzTest########################################## +ohos_fuzztest("FsFuzzer") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/fs_fuzzer" + + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "fs_fuzzer.cpp" ] + deps = [] +# deps = [":FsFuzzer",] + + defines = [ + "ACCOUNT_LOG_TAG = \"FsFuzzTer\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +############################################################################### + +############################################################################### diff --git a/hc_node/hc_enable_fuzzer/corpus/init b/hc_node/hc_enable_fuzzer/corpus/init new file mode 100644 index 0000000..59aefb5 --- /dev/null +++ b/hc_node/hc_enable_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/hc_node/hc_enable_fuzzer/fs_fuzzer.cpp b/hc_node/hc_enable_fuzzer/fs_fuzzer.cpp new file mode 100644 index 0000000..0bed2e3 --- /dev/null +++ b/hc_node/hc_enable_fuzzer/fs_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "fs_fuzzer.h" + +const char *dev_hc_enable = "/sys/fs/f2fs/loop1/hc_enable"; + +namespace OHOS { +bool FsFuzzer(const uint8_t *data, size_t size) +{ + char buffer[size]; + int fd = open(dev_hc_enable, RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_hc_enable); + return false; + } + int ret = read(fd, buffer, sizeof(char)); + if(ret == 0){ + printf("%s read success", dev_hc_enable); + } + ret = write(fd, data, sizeof(char)); + if(ret == 0){ + printf("%s write success", dev_hc_enable); + } + close(fd); + return true; + + +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + OHOS::FsFuzzer(data, size); + return 0; +} + diff --git a/hc_node/hc_enable_fuzzer/fs_fuzzer.h b/hc_node/hc_enable_fuzzer/fs_fuzzer.h new file mode 100644 index 0000000..3e9b4aa --- /dev/null +++ b/hc_node/hc_enable_fuzzer/fs_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 FS_FUZZER_H_ +#define FS_FUZZER_H_ + +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // FS_FUZZER_H_ \ No newline at end of file diff --git a/hc_node/hc_enable_fuzzer/project.xml b/hc_node/hc_enable_fuzzer/project.xml new file mode 100644 index 0000000..85e7ef2 --- /dev/null +++ b/hc_node/hc_enable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hc_node/hc_hot_data_lower_limit_fuzzer/BUILD.gn b/hc_node/hc_hot_data_lower_limit_fuzzer/BUILD.gn new file mode 100644 index 0000000..9e1dc26 --- /dev/null +++ b/hc_node/hc_hot_data_lower_limit_fuzzer/BUILD.gn @@ -0,0 +1,48 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +##############################HotDataLowerLimitFuzzer########################################## +ohos_fuzztest("HotDataLowerLimitFuzzer") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/hot_data_lower_limit_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hot_data_lower_limit_fuzzer.cpp" ] + deps = [ + "//utils/native/base:utils", + ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HotDataLowerLimitFuzzer" ] +} \ No newline at end of file diff --git a/hc_node/hc_hot_data_lower_limit_fuzzer/corpus/init b/hc_node/hc_hot_data_lower_limit_fuzzer/corpus/init new file mode 100644 index 0000000..59aefb5 --- /dev/null +++ b/hc_node/hc_hot_data_lower_limit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.cpp b/hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.cpp new file mode 100644 index 0000000..64d0c51 --- /dev/null +++ b/hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.cpp @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "hot_data_lower_limit_fuzzer.h" + +const char hcHotDataLowerLimit[] = "/sys/fs/f2fs/loop1/hc_hot_data_lower_limit"; + +namespace OHOS { + +/*static bool OpenCloseHcEnable(uint32_t data, size_t size) +{ + char buffer[size]; + int fd = open(devHcEnable, RDWR); + if (fd < 0) { + printf("open %s failed\n", devHcEnable); + return false; + } + int ret = read(fd, buffer, size); + if(ret > 0){ + printf("%s read success\n", devHcEnable); + } + if(ret < 0){ + printf("%s read fail, data = %d\n", devHcEnable, data); + return false; + } + if(ret == 0){ + printf("%s read finish\n", devHcEnable); + } + ret = write(fd, (void *)data, size); + if(ret > 0){ + printf("%s write success\n", devHcEnable); + } + if(ret < 0){ + printf("%s write fail\n", devHcEnable); + return false; + } + return true; +} +*/ +bool HcHotDataLowerLimitFuzzer(const uint8_t* data, size_t size) +{ + // uint32_t dataOpenClose = 1; + // OpenCloseHcEnable(dataOpenClose, sizeof(uint32_t)); + char buffer[size]; + int fd = open(hcHotDataLowerLimit, RDWR); + if (fd < 0) { + printf("open %s failed\n", hcHotDataLowerLimit); + return false; + } + int ret = read(fd, buffer, size); + if(ret > 0){ + printf("%s read success\n", hcHotDataLowerLimit); + } + if(ret < 0){ + printf("%s read fail, data = %s\n", hcHotDataLowerLimit, data); + return false; + } + if(ret == 0){ + printf("%s read finish\n", hcHotDataLowerLimit); + } + ret = write(fd, data, size); + if(ret == 0){ + printf("%s write success\n", hcHotDataLowerLimit); + } + close(fd); + return true; +} + +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + OHOS::HcHotDataLowerLimitFuzzer(data, size); + return 0; +} + diff --git a/hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.h b/hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.h new file mode 100644 index 0000000..565a3c5 --- /dev/null +++ b/hc_node/hc_hot_data_lower_limit_fuzzer/hot_data_lower_limit_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 HOT_DATA_LOWER_LIMIT_FUZZER_H_ +#define HOT_DATA_LOWER_LIMIT_FUZZER_H_ + +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // HOT_DATA_LOWER_LIMIT_FUZZER_H_ \ No newline at end of file diff --git a/hc_node/hc_hot_data_lower_limit_fuzzer/project.xml b/hc_node/hc_hot_data_lower_limit_fuzzer/project.xml new file mode 100644 index 0000000..2409e4e --- /dev/null +++ b/hc_node/hc_hot_data_lower_limit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 100 + + 4096 + + diff --git a/hc_node/hc_hot_data_waterline_fuzzer/BUILD.gn b/hc_node/hc_hot_data_waterline_fuzzer/BUILD.gn new file mode 100644 index 0000000..b5632c2 --- /dev/null +++ b/hc_node/hc_hot_data_waterline_fuzzer/BUILD.gn @@ -0,0 +1,48 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +##############################HotDataWaterlineFuzzer########################################## +ohos_fuzztest("HotDataWaterlineFuzzer") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/hot_data_waterline_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hot_data_waterline_fuzzer.cpp" ] + deps = [ + "//utils/native/base:utils", + ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HotDataWaterlineFuzzer" ] +} \ No newline at end of file diff --git a/hc_node/hc_hot_data_waterline_fuzzer/corpus/init b/hc_node/hc_hot_data_waterline_fuzzer/corpus/init new file mode 100644 index 0000000..59aefb5 --- /dev/null +++ b/hc_node/hc_hot_data_waterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.cpp b/hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.cpp new file mode 100644 index 0000000..36bb848 --- /dev/null +++ b/hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.cpp @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "hot_data_waterline_fuzzer.h" + + +const char hcHotDataWaterLine[] = "/sys/fs/f2fs/loop1/hc_hot_data_waterline"; + +namespace OHOS { + +/*static bool OpenCloseHcEnable(uint32_t data, size_t size) +{ + char buffer[size]; + int fd = open(devHcEnable, RDWR); + if (fd < 0) { + printf("open %s failed\n", devHcEnable); + return false; + } + int ret = read(fd, buffer, size); + if(ret > 0){ + printf("%s read success\n", devHcEnable); + } + if(ret < 0){ + printf("%s read fail, data = %d\n", devHcEnable, data); + return false; + } + if(ret == 0){ + printf("%s read finish\n", devHcEnable); + } + ret = write(fd, (void *)data, size); + if(ret > 0){ + printf("%s write success\n", devHcEnable); + } + if(ret < 0){ + printf("%s write fail\n", devHcEnable); + return false; + } + return true; +} +*/ +bool HcHotDataWaterLineFuzzer(const uint8_t* data, size_t size) +{ + // uint32_t dataOpenClose = 1; + // OpenCloseHcEnable(dataOpenClose, sizeof(uint32_t)); + char buffer[size]; + int fd = open(hcHotDataWaterLine, RDWR); + if (fd < 0) { + printf("open %s failed\n", hcHotDataWaterLine); + return false; + } + int ret = read(fd, buffer, size); + if(ret > 0){ + printf("%s read success\n", hcHotDataWaterLine); + } + if(ret < 0){ + printf("%s read fail, data = %s\n", hcHotDataWaterLine, data); + return false; + } + if(ret == 0){ + printf("%s read finish\n", hcHotDataWaterLine); + } + ret = write(fd, data, size); + if(ret == 0){ + printf("%s write success\n", hcHotDataWaterLine); + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + OHOS::HcHotDataWaterLineFuzzer(data, size); + return 0; +} + diff --git a/hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.h b/hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.h new file mode 100644 index 0000000..29de3c2 --- /dev/null +++ b/hc_node/hc_hot_data_waterline_fuzzer/hot_data_waterline_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 HOT_DATA_WATERLINE_FUZZER_H_ +#define HOT_DATA_WATERLINE_FUZZER_H_ + +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // HOT_DATA_WATERLINE_FUZZER_H_ \ No newline at end of file diff --git a/hc_node/hc_hot_data_waterline_fuzzer/project.xml b/hc_node/hc_hot_data_waterline_fuzzer/project.xml new file mode 100644 index 0000000..2409e4e --- /dev/null +++ b/hc_node/hc_hot_data_waterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 100 + + 4096 + + diff --git a/hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn b/hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn new file mode 100644 index 0000000..ff58a17 --- /dev/null +++ b/hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn @@ -0,0 +1,48 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +##############################FsFuzzTest########################################## +ohos_fuzztest("HcHotNodeLowerLimitFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/hchotnodelowerlimit_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hchotnodelowerlimit_fuzzer.cpp" ] + deps = [ + "//utils/native/base:utils", + ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcHotNodeLowerLimitFuzzTest" ] +} \ No newline at end of file diff --git a/hc_node/hchotnodelowerlimit_fuzzer/corpus/init b/hc_node/hchotnodelowerlimit_fuzzer/corpus/init new file mode 100644 index 0000000..59aefb5 --- /dev/null +++ b/hc_node/hchotnodelowerlimit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp b/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp new file mode 100644 index 0000000..b5d9026 --- /dev/null +++ b/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "hchotnodelowerlimit_fuzzer.h" + +const char hc_hot_node_lower_limit[] = "/sys/fs/f2fs/loop1/hc_hot_node_lower_limit"; + +namespace OHOS { + +bool HcHotNodeLowerLimit(const uint8_t* data, size_t size) +{ + char buffer[sizeof(char)]; + int fd = open(hc_hot_node_lower_limit, RDWR); + if (fd < 0) { + printf("open %s failed\r\n", hc_hot_node_lower_limit); + return false; + } + int ret = read(fd,buffer,sizeof(char)); + if(ret == 0){ + printf("%s read success", hc_hot_node_lower_limit); + } + ret = write(fd, data, sizeof(char)); + + if(ret == 0){ + printf("%s write success", hc_hot_node_lower_limit); + } + close(fd); + return true; +} + +}// namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + OHOS::HcHotNodeLowerLimit(data, size); + return 0; +} + diff --git a/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.h b/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.h new file mode 100644 index 0000000..05f4956 --- /dev/null +++ b/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 HCHOTNODELOWERLIMIT_FUZZER_H_ +#define HCHOTNODELOWERLIMIT_FUZZER_H_ + +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // HCHOTNODELOWERLIMIT_FUZZER_H_ diff --git a/hc_node/hchotnodelowerlimit_fuzzer/project.xml b/hc_node/hchotnodelowerlimit_fuzzer/project.xml new file mode 100644 index 0000000..85e7ef2 --- /dev/null +++ b/hc_node/hchotnodelowerlimit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hc_node/hchotnodewaterline_fuzzer/BUILD.gn b/hc_node/hchotnodewaterline_fuzzer/BUILD.gn new file mode 100644 index 0000000..025db28 --- /dev/null +++ b/hc_node/hchotnodewaterline_fuzzer/BUILD.gn @@ -0,0 +1,48 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +##############################FsFuzzTest########################################## +ohos_fuzztest("HcHotNodeWaterLineFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/hchotnodewaterline_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hchotnodewaterline_fuzzer.cpp" ] + deps = [ + "//utils/native/base:utils", + ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcHotNodeWaterLineFuzzTest" ] +} \ No newline at end of file diff --git a/hc_node/hchotnodewaterline_fuzzer/corpus/init b/hc_node/hchotnodewaterline_fuzzer/corpus/init new file mode 100644 index 0000000..59aefb5 --- /dev/null +++ b/hc_node/hchotnodewaterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp b/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp new file mode 100644 index 0000000..8dc52dd --- /dev/null +++ b/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "hchotnodewaterline_fuzzer.h" + +const char hc_hot_node_waterline[] = "/sys/fs/f2fs/loop1/hc_hot_node_waterline"; + +namespace OHOS { +bool HcHotNodeWaterline(const uint8_t* data, size_t size) +{ + char buffer[sizeof(char)]; + int fd = open(hc_hot_node_waterline, RDWR); + if (fd < 0) { + printf("open %s failed\r\n", hc_hot_node_waterline); + return false; + } + int ret = read(fd,buffer,sizeof(char)); + if(ret == 0){ + printf("%s read success", hc_hot_node_waterline); + } + ret = write(fd, data, sizeof(char)); + + if(ret == 0){ + printf("%s write success", hc_hot_node_waterline); + } + close(fd); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + OHOS::HcHotNodeWaterline(data, size); + return 0; +} + diff --git a/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.h b/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.h new file mode 100644 index 0000000..edca479 --- /dev/null +++ b/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 HCHOTNODEWATERLINE_FUZZER_H_ +#define HCHOTNODEWATERLINE_FUZZER_H_ + +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // HCHOTNODEWATERLINE_FUZZER_H_ diff --git a/hc_node/hchotnodewaterline_fuzzer/project.xml b/hc_node/hchotnodewaterline_fuzzer/project.xml new file mode 100644 index 0000000..85e7ef2 --- /dev/null +++ b/hc_node/hchotnodewaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn b/hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn new file mode 100644 index 0000000..5b4c274 --- /dev/null +++ b/hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn @@ -0,0 +1,48 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +##############################HcWarmNodeLowerLimitFuzzTest########################################## +ohos_fuzztest("HcWarmNodeLowerLimitFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/hcwarmnodelowerlimit_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hcwarmnodelowerlimit_fuzzer.cpp" ] + deps = [ + "//utils/native/base:utils", + ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcWarmNodeLowerLimitFuzzTest" ] +} \ No newline at end of file diff --git a/hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init b/hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init new file mode 100644 index 0000000..59aefb5 --- /dev/null +++ b/hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp b/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp new file mode 100644 index 0000000..e6bcffe --- /dev/null +++ b/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "hcwarmnodelowerlimit_fuzzer.h" + +const char hc_warm_node_lower_limit[] = "/sys/fs/f2fs/loop1/hc_warm_node_lower_limit"; + +namespace OHOS { +bool HcWarmNodeLowerLimit(const uint8_t* data, size_t size) +{ + char buffer[sizeof(char)]; + int fd = open(hc_warm_node_lower_limit, RDWR); + if (fd < 0) { + printf("open %s failed", hc_warm_node_lower_limit); + return false; + } + + int ret = read(fd,buffer,sizeof(char)); + if(ret < 0) { + printf("read %s failed", hc_warm_node_lower_limit); + } + + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + OHOS::HcWarmNodeLowerLimit(data, size); + return 0; +} diff --git a/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.h b/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.h new file mode 100644 index 0000000..cde7b9e --- /dev/null +++ b/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 HC_WARM_NODE_LOWER_LIMIT_FUZZER +#define HC_WARM_NODE_LOWER_LIMIT_FUZZER + +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // HC_WARM_NODE_LOWER_LIMIT_FUZZER \ No newline at end of file diff --git a/hc_node/hcwarmnodelowerlimit_fuzzer/project.xml b/hc_node/hcwarmnodelowerlimit_fuzzer/project.xml new file mode 100644 index 0000000..85e7ef2 --- /dev/null +++ b/hc_node/hcwarmnodelowerlimit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn b/hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn new file mode 100644 index 0000000..0fb5a97 --- /dev/null +++ b/hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn @@ -0,0 +1,48 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +##############################HcWarmNodeWaterLineFuzzTest########################################## +ohos_fuzztest("HcWarmNodeWaterLineFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/hcwarmnodewaterline_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hcwarmnodewaterline_fuzzer.cpp" ] + deps = [ + "//utils/native/base:utils", + ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcWarmNodeWaterLineFuzzTest" ] +} \ No newline at end of file diff --git a/hc_node/hcwarmnodewaterline_fuzzer/corpus/init b/hc_node/hcwarmnodewaterline_fuzzer/corpus/init new file mode 100644 index 0000000..59aefb5 --- /dev/null +++ b/hc_node/hcwarmnodewaterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp b/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp new file mode 100644 index 0000000..faa62e8 --- /dev/null +++ b/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "hcwarmnodewaterline_fuzzer.h" + +const char hc_warm_node_waterline[] = "/sys/fs/f2fs/loop1/hc_warm_node_waterline"; + +namespace OHOS { +bool HcWarmNodeLowerWaterLine(const uint8_t* data, size_t size) +{ + char buffer[sizeof(char)]; + int fd = open(hc_warm_node_waterline, RDWR); + if (fd < 0) { + printf("open %s failed", hc_warm_node_waterline); + return false; + } + + int ret = read(fd,buffer,sizeof(char)); + if(ret < 0) { + printf("read %s failed", hc_warm_node_waterline); + } + + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + OHOS::HcWarmNodeLowerWaterLine(data, size); + return 0; +} diff --git a/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.h b/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.h new file mode 100644 index 0000000..9491c27 --- /dev/null +++ b/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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 HC_WARM_NODE_LOWER_WATERLINE_FUZZER +#define HC_WARM_NODE_LOWER_WATERLINE_FUZZER + +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // HC_WARM_NODE_LOWER_WATERLINE_FUZZER \ No newline at end of file diff --git a/hc_node/hcwarmnodewaterline_fuzzer/project.xml b/hc_node/hcwarmnodewaterline_fuzzer/project.xml new file mode 100644 index 0000000..85e7ef2 --- /dev/null +++ b/hc_node/hcwarmnodewaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hc_node/warmdatalowerlimit_fuzzer/BUILD.gn b/hc_node/warmdatalowerlimit_fuzzer/BUILD.gn new file mode 100644 index 0000000..6def166 --- /dev/null +++ b/hc_node/warmdatalowerlimit_fuzzer/BUILD.gn @@ -0,0 +1,47 @@ +# 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("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/services" + +##############################fuzztest########################################## +ohos_fuzztest("WarmDataLowerLimitFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/notification/ans_standard/test/fuzztest/warmdatalowerlimit_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "warmdatalowerlimit_fuzzer.cpp" ] + + deps = [ + "//utils/native/base:utils", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":WarmDataLowerLimitFuzzTest" ] +} +############################################################################### diff --git a/hc_node/warmdatalowerlimit_fuzzer/corpus/init b/hc_node/warmdatalowerlimit_fuzzer/corpus/init new file mode 100644 index 0000000..1b91014 --- /dev/null +++ b/hc_node/warmdatalowerlimit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/hc_node/warmdatalowerlimit_fuzzer/project.xml b/hc_node/warmdatalowerlimit_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/hc_node/warmdatalowerlimit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.cpp b/hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.cpp new file mode 100644 index 0000000..c35d235 --- /dev/null +++ b/hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.cpp @@ -0,0 +1,43 @@ +/* + * 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 "warmdatalowerlimit_fuzzer.h" +const char dev_hc_enable[] = "/sys/fs/f2fs/loop1/hc_warm_data_lower_limit"; + +namespace OHOS { + bool WarmDataLowerLimitFuzzTest(const uint8_t* data, size_t size) + { + char buffer[sizeof(char)]; + int fd = open(dev_hc_enable, RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_hc_enable); + return false; + } + int ret = read(fd,buffer,sizeof(char)); + if(ret == 0){ + printf("%s read success", dev_hc_enable); + } + close(fd); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::WarmDataLowerLimitFuzzTest(data, size); + return 0; +} diff --git a/hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.h b/hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.h new file mode 100644 index 0000000..203d6c7 --- /dev/null +++ b/hc_node/warmdatalowerlimit_fuzzer/warmdatalowerlimit_fuzzer.h @@ -0,0 +1,32 @@ +/* + * 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 TEST_FUZZTEST_WARMDATALOWERLIMIT_FUZZER_H +#define TEST_FUZZTEST_WARMDATALOWERLIMIT_FUZZER_H + +#include +#include +#include +#include +#include +#include +#include + +#define FUZZ_PROJECT_NAME "warmdatalowerlimit_fuzzer" +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // TEST_FUZZTEST_WARMDATALOWERLIMIT_FUZZER_H \ No newline at end of file diff --git a/hc_node/warmdatawaterline_fuzzer/BUILD.gn b/hc_node/warmdatawaterline_fuzzer/BUILD.gn new file mode 100644 index 0000000..987e341 --- /dev/null +++ b/hc_node/warmdatawaterline_fuzzer/BUILD.gn @@ -0,0 +1,47 @@ +# 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("//base/notification/ans_standard/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "ans_standard/services" + +##############################fuzztest########################################## +ohos_fuzztest("WarmDataWaterLineFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/notification/ans_standard/test/fuzztest/warmdatawaterline_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "warmdatawaterline_fuzzer.cpp" ] + + deps = [ + "//utils/native/base:utils", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":WarmDataWaterLineFuzzTest" ] +} +############################################################################### diff --git a/hc_node/warmdatawaterline_fuzzer/corpus/init b/hc_node/warmdatawaterline_fuzzer/corpus/init new file mode 100644 index 0000000..1b91014 --- /dev/null +++ b/hc_node/warmdatawaterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/hc_node/warmdatawaterline_fuzzer/project.xml b/hc_node/warmdatawaterline_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/hc_node/warmdatawaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.cpp b/hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.cpp new file mode 100644 index 0000000..439605f --- /dev/null +++ b/hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.cpp @@ -0,0 +1,43 @@ +/* + * 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 "warmdatawaterline_fuzzer.h" +const char dev_hc_enable[] = "/sys/fs/f2fs/loop1/hc_warm_data_waterline"; + +namespace OHOS { + bool WarmDataWaterLineFuzzTest(const uint8_t* data, size_t size) + { + char buffer[sizeof(char)]; + int fd = open(dev_hc_enable, RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_hc_enable); + return false; + } + int ret = read(fd,buffer,sizeof(char)); + if(ret == 0){ + printf("%s read success", dev_hc_enable); + } + close(fd); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::WarmDataWaterLineFuzzTest(data, size); + return 0; +} diff --git a/hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.h b/hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.h new file mode 100644 index 0000000..3346f7e --- /dev/null +++ b/hc_node/warmdatawaterline_fuzzer/warmdatawaterline_fuzzer.h @@ -0,0 +1,32 @@ +/* + * 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 TEST_FUZZTEST_WARMDATAWATERLINE_FUZZER_H +#define TEST_FUZZTEST_WARMDATAWATERLINE_FUZZER_H + +#include +#include +#include +#include +#include +#include +#include + +#define FUZZ_PROJECT_NAME "warmdatawaterline_fuzzer" +#define RDONLY 00000000 +#define WRONLY 00000001 +#define RDWR 00000002 + +#endif // TEST_FUZZTEST_WARMDATAWATERLINE_FUZZER_H \ No newline at end of file diff --git a/ioctl/getftokenid_fuzzer/BUILD.gn b/ioctl/getftokenid_fuzzer/BUILD.gn new file mode 100644 index 0000000..b0c756d --- /dev/null +++ b/ioctl/getftokenid_fuzzer/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("GetfTokenidFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/getftokenid_fuzzer" + + include_dirs = [ + "accesstokenid_getftokenid.h", + "getftokenid_fuzzer.h", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "accesstokenid_getftokenid.cpp", + "getftokenid_fuzzer.cpp", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.cpp b/ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.cpp new file mode 100644 index 0000000..ca264b5 --- /dev/null +++ b/ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.cpp @@ -0,0 +1,51 @@ +/* + * 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 "accesstokenid_getftokenid.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; +constexpr unsigned int GET_FTOKEN_ID = 3; + + +#define ACCESS_TOKENID_GET_FTOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) + +const char dev_accesstokenid[] = "/dev/access_token_id"; + +int GetfTokenid(unsigned long long *ftoken) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); + if (ret) { + printf("ioctl ACCESS_TOKENID_GET_FTOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.h b/ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.h new file mode 100644 index 0000000..31c357e --- /dev/null +++ b/ioctl/getftokenid_fuzzer/accesstokenid_getftokenid.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021-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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace Security { +namespace AccessToken { + int GetfTokenid(unsigned long long *ftoken); +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/ioctl/getftokenid_fuzzer/corpus/init b/ioctl/getftokenid_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/ioctl/getftokenid_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/ioctl/getftokenid_fuzzer/getftokenid_fuzzer.cpp b/ioctl/getftokenid_fuzzer/getftokenid_fuzzer.cpp new file mode 100644 index 0000000..0a4f43c --- /dev/null +++ b/ioctl/getftokenid_fuzzer/getftokenid_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * 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 "getftokenid_fuzzer.h" + +#include +#include +#include + + +#include "accesstokenid_getftokenid.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { + bool GetfTokenidFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + constexpr size_t SIZE_MAX_LEN = 64; + char testdata[SIZE_MAX_LEN]; + if ((data == nullptr) || (size <= 0)) { + return result; + } + + if (size >= 64) + { + size = 64; + } + + memcpy(testdata, reinterpret_cast(data), SIZE_MAX_LEN); + result = GetfTokenid((unsigned long long*)testdata); + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GetfTokenidFuzzTest(data, size); + return 0; +} diff --git a/ioctl/getftokenid_fuzzer/getftokenid_fuzzer.h b/ioctl/getftokenid_fuzzer/getftokenid_fuzzer.h new file mode 100644 index 0000000..15a9e1d --- /dev/null +++ b/ioctl/getftokenid_fuzzer/getftokenid_fuzzer.h @@ -0,0 +1,6 @@ +#ifndef TEST_FUZZTEST_GETFTOKENID_FUZZER_H +#define TEST_FUZZTEST_GETFTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "getftokenid_fuzzer" + +#endif // TEST_FUZZTEST_GETFTOKENID_FUZZER_H \ No newline at end of file diff --git a/ioctl/getftokenid_fuzzer/project.xml b/ioctl/getftokenid_fuzzer/project.xml new file mode 100644 index 0000000..46f9b9b --- /dev/null +++ b/ioctl/getftokenid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/ioctl/gettokenidcmdcorrect_fuzzer/BUILD.gn b/ioctl/gettokenidcmdcorrect_fuzzer/BUILD.gn new file mode 100644 index 0000000..746bd0f --- /dev/null +++ b/ioctl/gettokenidcmdcorrect_fuzzer/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("GetTokenidCmdCorrectFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/gettokenidcmdcorrect_fuzzer" + + include_dirs = [ + "accesstokenid.h", + "gettokenidcmdcorrect_fuzzer.h", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "accesstokenid.cpp", + "gettokenidcmdcorrect_fuzzer.cpp", + "accesstokenid.h", + "gettokenidcmdcorrect_fuzzer.h", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.cpp b/ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.cpp new file mode 100644 index 0000000..d25b2ad --- /dev/null +++ b/ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.cpp @@ -0,0 +1,75 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "accesstokenid.h" +#include +#include + +namespace OHOS { +namespace Security { +namespace AccessToken { +constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; +constexpr unsigned int GET_TOKEN_ID = 1; +#define ACCESS_TOKENID_GET_TOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) + +//constexpr unsigned long long INVAL_TOKEN = 0xffffffffffffffff; + + +const char dev_accesstokenid[] = "/dev/access_token_id"; + +struct tokeninfo { + pid_t pid; + pid_t tid; + unsigned long long tokenid; + unsigned long long ftokenid; +}; + +int GetTokenid(unsigned long long *token) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); + if (ret) { + printf("ioctl ACCESS_TOKENID_GET_TOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.h b/ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.h new file mode 100644 index 0000000..5202a7e --- /dev/null +++ b/ioctl/gettokenidcmdcorrect_fuzzer/accesstokenid.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021-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 +#include + + + +namespace OHOS { +namespace Security { +namespace AccessToken { + int GetTokenid(unsigned long long *token); +// static int SetTokenid(unsigned long long *token); +// static int GetfTokenid(unsigned long long *ftoken); +// static int SetfTokenid(unsigned long long *ftoken); +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/gettokenidcmdcorrect_fuzzer/corpus/init b/ioctl/gettokenidcmdcorrect_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/ioctl/gettokenidcmdcorrect_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp b/ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp new file mode 100644 index 0000000..7e82871 --- /dev/null +++ b/ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include "gettokenidcmdcorrect_fuzzer.h" + +#include +#include +#include +#include +#undef private + +#include "accesstokenid.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { + bool GetTokenidCmdCorrectFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > sizeof(unsigned long long)) { + uint8_t testdata[8] = "ohos"; + void* data_addr = (void*)testdata; + data_addr = memcpy(data_addr, data, sizeof(unsigned long long)); + unsigned long long TOKENID = reinterpret_cast(data_addr); + result = GetTokenid(&TOKENID); + } else { + unsigned long long TOKENID = reinterpret_cast(data); + result = GetTokenid(&TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GetTokenidCmdCorrectFuzzTest(data, size); + return 0; +} diff --git a/ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h b/ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h new file mode 100644 index 0000000..3406d6a --- /dev/null +++ b/ioctl/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h @@ -0,0 +1,6 @@ +#ifndef TEST_FUZZTEST_GETTOKENID_FUZZER_H +#define TEST_FUZZTEST_GETTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "gettokenid_fuzzer" + +#endif // TEST_FUZZTEST_DELETETOKEN_FUZZER_H diff --git a/ioctl/gettokenidcmdcorrect_fuzzer/project.xml b/ioctl/gettokenidcmdcorrect_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/ioctl/gettokenidcmdcorrect_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/ioctl/gettokenidcmderror_fuzzer/BUILD.gn b/ioctl/gettokenidcmderror_fuzzer/BUILD.gn new file mode 100644 index 0000000..0413eb3 --- /dev/null +++ b/ioctl/gettokenidcmderror_fuzzer/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("GetTokenidCmdErrorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/gettokenidcmderror_fuzzer" + + include_dirs = [ + "accesstokenid.h", + "gettokenidcmderror_fuzzer.h", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "accesstokenid.cpp", + "gettokenidcmderror_fuzzer.cpp", + "accesstokenid.h", + "gettokenidcmderror_fuzzer.h", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/ioctl/gettokenidcmderror_fuzzer/accesstokenid.cpp b/ioctl/gettokenidcmderror_fuzzer/accesstokenid.cpp new file mode 100644 index 0000000..7c319bc --- /dev/null +++ b/ioctl/gettokenidcmderror_fuzzer/accesstokenid.cpp @@ -0,0 +1,76 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "accesstokenid.h" +#include +#include + +namespace OHOS { +namespace Security { +namespace AccessToken { +constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; +constexpr unsigned int GET_TOKEN_ID = 0; +#define ACCESS_TOKENID_GET_TOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) + +//constexpr unsigned long long INVAL_TOKEN = 0xffffffffffffffff; + + +const char dev_accesstokenid[] = "/dev/access_token_id"; + +struct tokeninfo { + pid_t pid; + pid_t tid; + unsigned long long tokenid; + unsigned long long ftokenid; +}; + +int GetTokenid(unsigned long long *token) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); + if (ret) { + printf("ioctl ACCESS_TOKENID_GET_TOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/gettokenidcmderror_fuzzer/accesstokenid.h b/ioctl/gettokenidcmderror_fuzzer/accesstokenid.h new file mode 100644 index 0000000..5202a7e --- /dev/null +++ b/ioctl/gettokenidcmderror_fuzzer/accesstokenid.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021-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 +#include + + + +namespace OHOS { +namespace Security { +namespace AccessToken { + int GetTokenid(unsigned long long *token); +// static int SetTokenid(unsigned long long *token); +// static int GetfTokenid(unsigned long long *ftoken); +// static int SetfTokenid(unsigned long long *ftoken); +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/gettokenidcmderror_fuzzer/corpus/init b/ioctl/gettokenidcmderror_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/ioctl/gettokenidcmderror_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp b/ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp new file mode 100644 index 0000000..88533e1 --- /dev/null +++ b/ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "gettokenidcmderror_fuzzer.h" + +#include +#include +#include +#undef private + +#include "accesstokenid.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { + bool GetTokenidCmdErrorFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > sizeof(unsigned long long)) { + uint8_t testdata[8] = "ohos"; + void* data_addr = (void*)testdata; + data_addr = memcpy(data_addr, data, sizeof(unsigned long long)); + unsigned long long TOKENID = reinterpret_cast(data_addr); + result = GetTokenid(&TOKENID); + } else { + unsigned long long TOKENID = reinterpret_cast(data); + result = GetTokenid(&TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GetTokenidCmdErrorFuzzTest(data, size); + return 0; +} diff --git a/ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h b/ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h new file mode 100644 index 0000000..3406d6a --- /dev/null +++ b/ioctl/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h @@ -0,0 +1,6 @@ +#ifndef TEST_FUZZTEST_GETTOKENID_FUZZER_H +#define TEST_FUZZTEST_GETTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "gettokenid_fuzzer" + +#endif // TEST_FUZZTEST_DELETETOKEN_FUZZER_H diff --git a/ioctl/gettokenidcmderror_fuzzer/project.xml b/ioctl/gettokenidcmderror_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/ioctl/gettokenidcmderror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/ioctl/setftokenid_fuzzer/BUILD.gn b/ioctl/setftokenid_fuzzer/BUILD.gn new file mode 100644 index 0000000..6565aa3 --- /dev/null +++ b/ioctl/setftokenid_fuzzer/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("SetfTokenidFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/setftokenid_fuzzer" + + include_dirs = [ + "accesstokenid_setftokenid.h", + "setftokenid_fuzzer.h", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "accesstokenid_setftokenid.cpp", + "setftokenid_fuzzer.cpp", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.cpp b/ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.cpp new file mode 100644 index 0000000..692a3da --- /dev/null +++ b/ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.cpp @@ -0,0 +1,50 @@ +/* + * 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 "accesstokenid_setftokenid.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; +constexpr unsigned int SET_FTOKEN_ID = 4; + +#define ACCESS_TOKENID_SET_FTOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) + +const char dev_accesstokenid[] = "/dev/access_token_id"; + +int SetfTokenid(unsigned long long *ftoken) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); + if (ret) { + printf("ioctl ACCESS_TOKENID_SET_FTOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.h b/ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.h new file mode 100644 index 0000000..8c14426 --- /dev/null +++ b/ioctl/setftokenid_fuzzer/accesstokenid_setftokenid.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021-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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace Security { +namespace AccessToken { + int SetfTokenid(unsigned long long *ftoken); +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/ioctl/setftokenid_fuzzer/corpus/init b/ioctl/setftokenid_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/ioctl/setftokenid_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/ioctl/setftokenid_fuzzer/project.xml b/ioctl/setftokenid_fuzzer/project.xml new file mode 100644 index 0000000..46f9b9b --- /dev/null +++ b/ioctl/setftokenid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/ioctl/setftokenid_fuzzer/setftokenid_fuzzer.cpp b/ioctl/setftokenid_fuzzer/setftokenid_fuzzer.cpp new file mode 100644 index 0000000..a2e7843 --- /dev/null +++ b/ioctl/setftokenid_fuzzer/setftokenid_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * 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 "setftokenid_fuzzer.h" + +#include +#include +#include +#undef private + +#include "accesstokenid_setftokenid.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { + bool SetfTokenidFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + constexpr size_t SIZE_MAX_LEN = 64; + char testdata[SIZE_MAX_LEN]; + if ((data == nullptr) || (size <= 0)) { + return result; + } + + if (size >= 64) + { + size = 64; + } + + memcpy(testdata, reinterpret_cast(data), SIZE_MAX_LEN); + result = SetfTokenid((unsigned long long*)testdata); + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SetfTokenidFuzzTest(data, size); + return 0; +} diff --git a/ioctl/setftokenid_fuzzer/setftokenid_fuzzer.h b/ioctl/setftokenid_fuzzer/setftokenid_fuzzer.h new file mode 100644 index 0000000..91945ca --- /dev/null +++ b/ioctl/setftokenid_fuzzer/setftokenid_fuzzer.h @@ -0,0 +1,6 @@ +#ifndef TEST_FUZZTEST_SETFTOKENID_FUZZER_H +#define TEST_FUZZTEST_SETFTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "setftokenid_fuzzer" + +#endif // TEST_FUZZTEST_SETFTOKENID_FUZZER_H \ No newline at end of file diff --git a/ioctl/settokenidcmdcorrect_fuzzer/BUILD.gn b/ioctl/settokenidcmdcorrect_fuzzer/BUILD.gn new file mode 100644 index 0000000..8db03b0 --- /dev/null +++ b/ioctl/settokenidcmdcorrect_fuzzer/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("SetTokenidCmdCorrectFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/settokenidcmdcorrect_fuzzer" + + include_dirs = [ + "accesstokenid.h", + "settokenidcmdcorrect_fuzzer.h", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "accesstokenid.cpp", + "settokenidcmdcorrect_fuzzer.cpp", + "accesstokenid.h", + "settokenidcmdcorrect_fuzzer.h", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.cpp b/ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.cpp new file mode 100644 index 0000000..634046a --- /dev/null +++ b/ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.cpp @@ -0,0 +1,75 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "accesstokenid.h" +#include +#include + +namespace OHOS { +namespace Security { +namespace AccessToken { +constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; +constexpr unsigned int SET_TOKEN_ID = 2; +#define ACCESS_TOKENID_SET_TOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) +//constexpr unsigned long long INVAL_TOKEN = 0xffffffffffffffff; + + +const char dev_accesstokenid[] = "/dev/access_token_id"; + +struct tokeninfo { + pid_t pid; + pid_t tid; + unsigned long long tokenid; + unsigned long long ftokenid; +}; + +int SetTokenid(unsigned long long *token) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); + if (ret) { + printf("ioctl ACCESS_TOKENID_SET_TOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.h b/ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.h new file mode 100644 index 0000000..cff1d01 --- /dev/null +++ b/ioctl/settokenidcmdcorrect_fuzzer/accesstokenid.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021-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 +#include + + + +namespace OHOS { +namespace Security { +namespace AccessToken { + + int SetTokenid(unsigned long long *token); + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/settokenidcmdcorrect_fuzzer/corpus/init b/ioctl/settokenidcmdcorrect_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/ioctl/settokenidcmdcorrect_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/ioctl/settokenidcmdcorrect_fuzzer/project.xml b/ioctl/settokenidcmdcorrect_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/ioctl/settokenidcmdcorrect_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp b/ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp new file mode 100644 index 0000000..3f27465 --- /dev/null +++ b/ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include "settokenidcmdcorrect_fuzzer.h" + +#include +#include +#include +#include +#undef private + +#include "accesstokenid.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { + bool SetTokenidCmdCorrectFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > sizeof(unsigned long long)) { + uint8_t testdata[8] = "ohos"; + void* data_addr = (void*)testdata; + data_addr = memcpy(data_addr, data, sizeof(unsigned long long)); + unsigned long long TOKENID = reinterpret_cast(data_addr); + result = SetTokenid(&TOKENID); + } else { + unsigned long long TOKENID = reinterpret_cast(data); + result = SetTokenid(&TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SetTokenidCmdCorrectFuzzTest(data, size); + return 0; +} diff --git a/ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h b/ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h new file mode 100644 index 0000000..3406d6a --- /dev/null +++ b/ioctl/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h @@ -0,0 +1,6 @@ +#ifndef TEST_FUZZTEST_GETTOKENID_FUZZER_H +#define TEST_FUZZTEST_GETTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "gettokenid_fuzzer" + +#endif // TEST_FUZZTEST_DELETETOKEN_FUZZER_H diff --git a/ioctl/settokenidcmderror_fuzzer/BUILD.gn b/ioctl/settokenidcmderror_fuzzer/BUILD.gn new file mode 100644 index 0000000..27e5bbb --- /dev/null +++ b/ioctl/settokenidcmderror_fuzzer/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "access_token/access_token" + +ohos_fuzztest("SetTokenidCmdErrorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/settokenidcmderror_fuzzer" + + include_dirs = [ + "accesstokenid.h", + "settokenidcmderror_fuzzer.h", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "accesstokenid.cpp", + "settokenidcmderror_fuzzer.cpp", + "accesstokenid.h", + "settokenidcmderror_fuzzer.h", + ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} diff --git a/ioctl/settokenidcmderror_fuzzer/accesstokenid.cpp b/ioctl/settokenidcmderror_fuzzer/accesstokenid.cpp new file mode 100644 index 0000000..21af3f8 --- /dev/null +++ b/ioctl/settokenidcmderror_fuzzer/accesstokenid.cpp @@ -0,0 +1,75 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "accesstokenid.h" +#include +#include + +namespace OHOS { +namespace Security { +namespace AccessToken { +constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; +constexpr unsigned int SET_TOKEN_ID = 0; +#define ACCESS_TOKENID_SET_TOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) +//constexpr unsigned long long INVAL_TOKEN = 0xffffffffffffffff; + + +const char dev_accesstokenid[] = "/dev/access_token_id"; + +struct tokeninfo { + pid_t pid; + pid_t tid; + unsigned long long tokenid; + unsigned long long ftokenid; +}; + +int SetTokenid(unsigned long long *token) +{ + int fd = open(dev_accesstokenid, O_RDWR); + if (fd < 0) { + printf("open %s failed\r\n", dev_accesstokenid); + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); + if (ret) { + printf("ioctl ACCESS_TOKENID_SET_TOKENID failed\r\n"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/settokenidcmderror_fuzzer/accesstokenid.h b/ioctl/settokenidcmderror_fuzzer/accesstokenid.h new file mode 100644 index 0000000..cff1d01 --- /dev/null +++ b/ioctl/settokenidcmderror_fuzzer/accesstokenid.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021-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 +#include + + + +namespace OHOS { +namespace Security { +namespace AccessToken { + + int SetTokenid(unsigned long long *token); + +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/ioctl/settokenidcmderror_fuzzer/corpus/init b/ioctl/settokenidcmderror_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/ioctl/settokenidcmderror_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/ioctl/settokenidcmderror_fuzzer/project.xml b/ioctl/settokenidcmderror_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/ioctl/settokenidcmderror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp b/ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp new file mode 100644 index 0000000..1f8d47d --- /dev/null +++ b/ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "settokenidcmderror_fuzzer.h" + +#include +#include +#include +#undef private + +#include "accesstokenid.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { + bool SetTokenidCmdErrorFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > sizeof(unsigned long long)) { + uint8_t testdata[8] = "ohos"; + void* data_addr = (void*)testdata; + data_addr = memcpy(data_addr, data, sizeof(unsigned long long)); + unsigned long long TOKENID = reinterpret_cast(data_addr); + result = SetTokenid(&TOKENID); + } else { + unsigned long long TOKENID = reinterpret_cast(data); + result = SetTokenid(&TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SetTokenidCmdErrorFuzzTest(data, size); + return 0; +} diff --git a/ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h b/ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h new file mode 100644 index 0000000..3406d6a --- /dev/null +++ b/ioctl/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h @@ -0,0 +1,6 @@ +#ifndef TEST_FUZZTEST_GETTOKENID_FUZZER_H +#define TEST_FUZZTEST_GETTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "gettokenid_fuzzer" + +#endif // TEST_FUZZTEST_DELETETOKEN_FUZZER_H -- Gitee