!117 fix Code duplication

Merge pull request !117 from 吴凡/master
This commit is contained in:
openharmony_ci
2022-07-19 07:35:46 +00:00
committed by Gitee
95 changed files with 596 additions and 1192 deletions
@@ -31,7 +31,7 @@ ohos_fuzztest("AccessfTokenidGrpTestFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"accessftokenidgrptest_fuzzer.cpp",
]
}
@@ -17,7 +17,7 @@
#include <cstddef>
#include <cstdint>
#include "__config"
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
@@ -31,7 +31,7 @@ ohos_fuzztest("AccessfTokenidGrpTestOtherFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"accessftokenidgrptestother_fuzzer.cpp",
]
}
@@ -17,7 +17,7 @@
#include <cstddef>
#include <cstdint>
#include "__config"
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
@@ -31,7 +31,7 @@ ohos_fuzztest("AccessfTokenidThreadTestFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"accessftokenidthreadtest_fuzzer.cpp",
]
}
@@ -17,7 +17,7 @@
#include <cstddef>
#include <cstdint>
#include "__config"
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
@@ -30,7 +30,7 @@ ohos_fuzztest("GetfTokenidCmdCorrectFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"getftokenidcmdcorrect_fuzzer.cpp",
]
}
@@ -17,20 +17,14 @@
#include <cstddef>
#include <cstdint>
#include "__config"
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = GetfTokenid(&tokenId);
}
bool ret = GetfTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -30,7 +30,7 @@ ohos_fuzztest("GetfTokenidCmdErrorFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"getftokenidcmderror_fuzzer.cpp",
]
}
@@ -14,21 +14,18 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#define CMDERROR
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = GetfTokenid(&tokenId);
}
bool ret = GetfTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -1,21 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H
#define TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H
#define FUZZ_PROJECT_NAME "getftokenidcmderror_fuzzer"
#endif // TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H
@@ -30,7 +30,7 @@ ohos_fuzztest("GetfTokenidNullptrFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"getftokenidnullptr_fuzzer.cpp",
]
}
@@ -19,7 +19,7 @@
#include <cstddef>
#include <cstdint>
#include "__config"
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
@@ -26,13 +26,7 @@ using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool GetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = GetTokenid(&tokenId);
}
bool ret = GetTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -1,21 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H
#define TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H
#define FUZZ_PROJECT_NAME "gettokenidcmdcorrect_fuzzer"
#endif // TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H
@@ -25,13 +25,7 @@ using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool GetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = GetTokenid(&tokenId);
}
bool ret = GetTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -1,71 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ACCESSFTOKENIDCOMMON_H
#define ACCESSFTOKENIDCOMMON_H
#include <cstdint>
#define FUZZ_PROJECT_NAME "accessftokenidcommon"
namespace OHOS {
namespace Kernel {
namespace AccessToken {
#define ACCESS_TOKEN_ID_IOCTL_BASE 'A'
#ifdef CMDERROR
constexpr unsigned int get_ftoken_id = 0;
constexpr unsigned int set_ftoken_id = 0;
#else
constexpr unsigned int get_ftoken_id = 3;
constexpr unsigned int set_ftoken_id = 4;
#endif
#define ACCESS_TOKENID_GET_FTOKENID \
_IOR(ACCESS_TOKEN_ID_IOCTL_BASE, get_ftoken_id, unsigned long long)
#define ACCESS_TOKENID_SET_FTOKENID \
_IOW(ACCESS_TOKEN_ID_IOCTL_BASE, set_ftoken_id, unsigned long long)
#define LIST_NUM_1 1
#define LIST_NUM_2 2
#define TEST_VALUE 123
#define CHILDREN_NUM 3
#define WAIT_FOR_SHELL_OP_TIME 1
#define FATHER_WAIT_TIME (WAIT_FOR_SHELL_OP_TIME * (CHILDREN_NUM + 1))
#define ACCESS_TOKEN_UID 3020
#define ACCESS_TOKEN_GRPID 3020
#define ACCESS_TOKEN_OTHER_UID 1234
#define ACCESS_TOKEN_OTHER_GRPID 1234
#define INVAL_TOKEN 0xffffffffffffffff
int GetfTokenid(unsigned long long *ftoken);
int SetfTokenid(unsigned long long *ftoken);
void SetUidAndGrp();
void SetUidAndGrpOther();
void GetCurfToken(unsigned long long *ftoken);
void SetRandfTokenAndCheck(unsigned long long *data_ftoken);
void fTokenTest(unsigned long long *data_ftoken);
void ThreadTest(unsigned long long *data_ftoken);
int AccessfTokenidThreadTest(uint8_t *data_ftoken);
int AccessfTokenidGrpTest(uint8_t *data_ftoken);
int AccessfTokenidGrpTestOther(uint8_t *data_ftoken);
} // namespace AccessToken
} // namespace Kernel
} // namespace OHOS
#endif // ACCESSTOKENIDCOMMON_H
@@ -27,15 +27,23 @@ namespace AccessToken {
#ifdef CMDERROR
constexpr unsigned int get_token_id = 0;
constexpr unsigned int set_token_id = 0;
constexpr unsigned int get_ftoken_id = 0;
constexpr unsigned int set_ftoken_id = 0;
#else
constexpr unsigned int get_token_id = 1;
constexpr unsigned int set_token_id = 2;
constexpr unsigned int get_ftoken_id = 3;
constexpr unsigned int set_ftoken_id = 4;
#endif
#define ACCESS_TOKENID_GET_TOKENID \
_IOR(ACCESS_TOKEN_ID_IOCTL_BASE, get_token_id, unsigned long long)
#define ACCESS_TOKENID_SET_TOKENID \
_IOW(ACCESS_TOKEN_ID_IOCTL_BASE, set_token_id, unsigned long long)
#define ACCESS_TOKENID_GET_FTOKENID \
_IOR(ACCESS_TOKEN_ID_IOCTL_BASE, get_ftoken_id, unsigned long long)
#define ACCESS_TOKENID_SET_FTOKENID \
_IOW(ACCESS_TOKEN_ID_IOCTL_BASE, set_ftoken_id, unsigned long long)
#define LIST_NUM_1 1
#define LIST_NUM_2 2
@@ -54,6 +62,8 @@ constexpr unsigned int set_token_id = 2;
int GetTokenid(unsigned long long *token);
int SetTokenid(unsigned long long *token);
int GetfTokenid(unsigned long long *ftoken);
int SetfTokenid(unsigned long long *ftoken);
void SetUidAndGrp();
void SetUidAndGrpOther();
@@ -64,6 +74,18 @@ void ThreadTest(unsigned long long *data_token);
int AccessTokenidThreadTest(uint8_t *data_token);
int AccessTokenidGrpTest(uint8_t *data_token);
int AccessTokenidGrpTestOther(uint8_t *data_token);
void GetCurfToken(unsigned long long *ftoken);
void SetRandfTokenAndCheck(unsigned long long *data_ftoken);
void fTokenTest(unsigned long long *data_ftoken);
void ThreadTest(unsigned long long *data_ftoken);
int AccessfTokenidThreadTest(uint8_t *data_ftoken);
int AccessfTokenidGrpTest(uint8_t *data_ftoken);
int AccessfTokenidGrpTestOther(uint8_t *data_ftoken);
bool SetfTokenidCmdFuzzTest(const uint8_t *data, size_t size);
bool GetfTokenidCmdFuzzTest(const uint8_t *data, size_t size);
bool SetTokenidCmdFuzzTest(const uint8_t *data, size_t size);
bool GetTokenidCmdFuzzTest(const uint8_t *data, size_t size);
} // namespace AccessToken
} // namespace Kernel
} // namespace OHOS
@@ -30,7 +30,7 @@ ohos_fuzztest("SetfTokenidCmdCorrectFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"setftokenidcmdcorrect_fuzzer.cpp",
]
}
@@ -17,20 +17,14 @@
#include <cstddef>
#include <cstdint>
#include "__config"
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool SetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = SetfTokenid(&tokenId);
}
bool ret = SetfTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -1,21 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_SETFTOKENIDCMDCORRECT_FUZZER_H
#define TEST_FUZZTEST_SETFTOKENIDCMDCORRECT_FUZZER_H
#define FUZZ_PROJECT_NAME "setftokenidcmdcorrect_fuzzer"
#endif // TEST_FUZZTEST_SETFTOKENIDCMDCORRECT_FUZZER_H
@@ -30,7 +30,7 @@ ohos_fuzztest("SetfTokenidCmdErrorFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"setftokenidcmderror_fuzzer.cpp",
]
}
@@ -18,20 +18,14 @@
#include <cstdint>
#include "__config"
#define CMDERROR
#include "accessftokenidcommon.h"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool SetfTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = SetfTokenid(&tokenId);
}
bool ret = SetfTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -1,21 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_SETFTOKENIDCMDERROR_FUZZER_H
#define TEST_FUZZTEST_SETFTOKENIDCMDERROR_FUZZER_H
#define FUZZ_PROJECT_NAME "setftokenidcmderror_fuzzer"
#endif // TEST_FUZZTEST_SETFTOKENIDCMDERROR_FUZZER_H
@@ -30,7 +30,7 @@ ohos_fuzztest("SetfTokenidNullptrFuzzTest") {
]
sources = [
"../src/accessftokenidcommon.cpp",
"../src/accesstokenidcommon.cpp",
"setftokenidnullptr_fuzzer.cpp",
]
}
@@ -16,7 +16,10 @@
*/
#include <vector>
#include "accessftokenidcommon.h"
#include <cstddef>
#include <cstdint>
#include "__config"
#include "accesstokenidcommon.h"
using namespace std;
using namespace OHOS::Kernel::AccessToken;
@@ -26,13 +26,7 @@ using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool SetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = SetTokenid(&tokenId);
}
bool ret = SetTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -1,21 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_SETTOKENIDCMDCORRECT_FUZZER_H
#define TEST_FUZZTEST_SETTOKENIDCMDCORRECT_FUZZER_H
#define FUZZ_PROJECT_NAME "settokenidcmdcorrect_fuzzer"
#endif // TEST_FUZZTEST_SETTOKENIDCMDCORRECT_FUZZER_H
@@ -14,6 +14,9 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#define CMDERROR
#include "accesstokenidcommon.h"
@@ -22,13 +25,7 @@ using namespace OHOS::Kernel::AccessToken;
namespace OHOS {
bool SetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = SetTokenid(&tokenId);
}
bool ret = SetTokenidCmdFuzzTest(data, size);
return ret;
}
}
@@ -1,192 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <fcntl.h>
#include <pthread.h>
#include <cstdint>
#include <sys/ioctl.h>
#include <unistd.h>
#include <bits/syscall.h>
#include <cstdio>
#include "accessftokenidcommon.h"
namespace OHOS {
namespace Kernel {
namespace AccessToken {
const char *DEVACCESSTOKENID = "/dev/access_token_id";
int GetfTokenid(unsigned long long *ftoken)
{
int fd = open(DEVACCESSTOKENID, O_RDWR);
if (fd < 0) {
return -1;
}
int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken);
if (ret) {
close(fd);
return -1;
}
close(fd);
return 0;
}
int SetfTokenid(unsigned long long *ftoken)
{
int fd = open(DEVACCESSTOKENID, O_RDWR);
if (fd < 0) {
return -1;
}
int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken);
if (ret) {
close(fd);
return -1;
}
close(fd);
return 0;
}
void SetUidAndGrp()
{
int ret = 0;
size_t groupListSize = LIST_NUM_2;
gid_t groupList[LIST_NUM_2] = {ACCESS_TOKEN_GRPID, TEST_VALUE};
ret = setgroups(groupListSize, groupList);
if (ret != 0) {
return;
}
ret = setuid(ACCESS_TOKEN_UID);
if (ret != 0) {
printf("SetUidAndGrp setuid error %d \n", ret);
}
return;
}
void SetUidAndGrpOther()
{
int ret = 0;
size_t groupListSize = LIST_NUM_1;
gid_t groupList[LIST_NUM_1] = {ACCESS_TOKEN_OTHER_GRPID};
ret = setgroups(groupListSize, groupList);
if (ret != 0) {
return;
}
ret = setuid(ACCESS_TOKEN_OTHER_UID);
if (ret != 0) {
printf("SetUidAndGrp setuid error %d \r\n", ret);
}
return;
}
void SetRandfTokenAndCheck(unsigned long long *data_ftoken)
{
pid_t pid = getpid();
pid_t tid = syscall(__NR_gettid);
unsigned long long ftoken = INVAL_TOKEN;
unsigned long long ftokenSet = *data_ftoken;
SetfTokenid(&ftokenSet);
GetfTokenid(&ftoken);
if (ftoken != ftokenSet) {
printf("pid:%d tid:%d ftoken test failed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
} else {
printf("pid:%d tid:%d ftoken test succeed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
}
sleep(WAIT_FOR_SHELL_OP_TIME);
GetfTokenid(&ftoken);
if (ftoken != ftokenSet) {
printf("pid:%d tid:%d ftoken test failed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
} else {
printf("pid:%d tid:%d ftoken test succeed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
}
return;
}
void *fTokenTest(void *data_ftoken)
{
SetRandfTokenAndCheck(static_cast<unsigned long long *>(data_ftoken));
return nullptr;
}
void ThreadTest(void *data_ftoken)
{
pthread_t id_1;
pthread_t id_2;
pthread_t id_3;
int ret = 0;
ret = pthread_create(&id_1, nullptr, fTokenTest, data_ftoken);
if (ret != 0) {
return;
}
ret = pthread_create(&id_2, nullptr, fTokenTest, data_ftoken);
if (ret != 0) {
return;
}
ret = pthread_create(&id_3, nullptr, fTokenTest, data_ftoken);
if (ret != 0) {
return;
}
pthread_join(id_1, nullptr);
pthread_join(id_2, nullptr);
pthread_join(id_3, nullptr);
return;
}
int AccessfTokenidThreadTest(uint8_t *data_ftoken)
{
fTokenTest(static_cast<void *>(data_ftoken));
ThreadTest(static_cast<void *>(data_ftoken));
return 0;
}
int AccessfTokenidGrpTest(uint8_t *data_ftoken)
{
SetUidAndGrp();
fTokenTest(static_cast<void *>(data_ftoken));
ThreadTest(static_cast<void *>(data_ftoken));
return 0;
}
int AccessfTokenidGrpTestOther(uint8_t *data_ftoken)
{
SetUidAndGrpOther();
fTokenTest(static_cast<void *>(data_ftoken));
ThreadTest(static_cast<void *>(data_ftoken));
return 0;
}
} // namespace AccessToken
} // namespace Kernel
} // namespace OHOS
@@ -184,6 +184,148 @@ int AccessTokenidGrpTestOther(uint8_t *data_token)
ThreadTest(static_cast<void *>(data_token));
return 0;
}
int GetfTokenid(unsigned long long *ftoken)
{
int fd = open(DEVACCESSTOKENID, O_RDWR);
if (fd < 0) {
return -1;
}
int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken);
if (ret) {
close(fd);
return -1;
}
close(fd);
return 0;
}
int SetfTokenid(unsigned long long *ftoken)
{
int fd = open(DEVACCESSTOKENID, O_RDWR);
if (fd < 0) {
return -1;
}
int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken);
if (ret) {
close(fd);
return -1;
}
close(fd);
return 0;
}
void SetRandfTokenAndCheck(unsigned long long *data_ftoken)
{
pid_t pid = getpid();
pid_t tid = syscall(__NR_gettid);
unsigned long long ftoken = INVAL_TOKEN;
unsigned long long ftokenSet = *data_ftoken;
SetfTokenid(&ftokenSet);
GetfTokenid(&ftoken);
if (ftoken != ftokenSet) {
printf("pid:%d tid:%d ftoken test failed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
} else {
printf("pid:%d tid:%d ftoken test succeed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
}
sleep(WAIT_FOR_SHELL_OP_TIME);
GetfTokenid(&ftoken);
if (ftoken != ftokenSet) {
printf("pid:%d tid:%d ftoken test failed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
} else {
printf("pid:%d tid:%d ftoken test succeed, ftoken:%llu ftokenSet:%llu\n",
pid, tid, ftoken, ftokenSet);
}
return;
}
void *fTokenTest(void *data_ftoken)
{
SetRandfTokenAndCheck(static_cast<unsigned long long *>(data_ftoken));
return nullptr;
}
int AccessfTokenidThreadTest(uint8_t *data_ftoken)
{
fTokenTest(static_cast<void *>(data_ftoken));
ThreadTest(static_cast<void *>(data_ftoken));
return 0;
}
int AccessfTokenidGrpTest(uint8_t *data_ftoken)
{
SetUidAndGrp();
fTokenTest(static_cast<void *>(data_ftoken));
ThreadTest(static_cast<void *>(data_ftoken));
return 0;
}
int AccessfTokenidGrpTestOther(uint8_t *data_ftoken)
{
SetUidAndGrpOther();
fTokenTest(static_cast<void *>(data_ftoken));
ThreadTest(static_cast<void *>(data_ftoken));
return 0;
}
bool SetfTokenidCmdFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = SetfTokenid(&tokenId);
}
return ret;
}
bool GetfTokenidCmdFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = GetfTokenid(&tokenId);
}
return ret;
}
bool GetTokenidCmdFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = GetTokenid(&tokenId);
}
return ret;
}
bool SetTokenidCmdFuzzTest(const uint8_t *data, size_t size)
{
bool ret = false;
if ((data == nullptr) || (size < sizeof(unsigned long long))) {
return ret;
} else {
unsigned long long tokenId = *(reinterpret_cast<const unsigned long long *>(data));
ret = SetTokenid(&tokenId);
}
return ret;
}
} // namespace AccessToken
} // namespace Kernel
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("HcEnableFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hcenable_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hcenable_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hcenable_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
const char *HC_ENABLE = "/sys/fs/f2fs/loop1/hc_enable";
namespace OHOS {
bool HcEnableFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_ENABLE, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_ENABLE);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_ENABLE, size);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("HcHotDataLowerLimitFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hchotdatalowerlimit_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hchotdatalowerlimit_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
const char *HC_HOT_DATA_LOWER_LIMIT = "/sys/fs/f2fs/loop1/hc_hot_data_lower_limit";
namespace OHOS {
bool HcHotDataLowerLimitFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_HOT_DATA_LOWER_LIMIT, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_HOT_DATA_LOWER_LIMIT);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_HOT_DATA_LOWER_LIMIT, size);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("HcHotDataWaterlineFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hchotdatawaterline_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hchotdatawaterline_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hchotdatawaterline_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
const char *HC_HOT_DATA_WATERLINE = "/sys/fs/f2fs/loop1/hc_hot_data_waterline";
namespace OHOS {
bool HcHotDataWaterlineFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_HOT_DATA_WATERLINE, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_HOT_DATA_WATERLINE);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_HOT_DATA_WATERLINE, size);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("HcHotNodeLowerLimitFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hchotnodelowerlimit_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hchotnodelowerlimit_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
const char *HC_HOT_NODE_LOWER_LIMIT = "/sys/fs/f2fs/loop1/hc_hot_node_lower_limit";
namespace OHOS {
bool HcHotNodeLowerLimitFuzzTest(const uint8_t *data, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_HOT_NODE_LOWER_LIMIT, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_HOT_NODE_LOWER_LIMIT);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_HOT_NODE_LOWER_LIMIT, size);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("HcHotNodeWaterLineFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hchotnodewaterline_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hchotnodewaterline_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hchotnodewaterline_fuzzer.cpp",
]
}
group("fuzztest") {
testonly = true
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
const char *HC_HOT_NODE_WATERLINE = "/sys/fs/f2fs/loop1/hc_hot_node_waterline";
namespace OHOS {
bool HcHotNodeWaterlineFuzzTest(const uint8_t *data, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_HOT_NODE_WATERLINE, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_HOT_NODE_WATERLINE);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_HOT_NODE_WATERLINE, size);
return ret;
}
} // namespace OHOS
@@ -20,13 +20,18 @@ ohos_fuzztest("HcWarmDataLowerLimitFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hcwarmdatalowerlimit_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hcwarmdatalowerlimit_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
const char *HC_WARM_DATA_LOWER_LIMIT = "/sys/fs/f2fs/loop1/hc_warm_data_lower_limit";
namespace OHOS {
bool HcWarmDataLowerLimitFuzzTest(const uint8_t *data, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_WARM_DATA_LOWER_LIMIT, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_WARM_DATA_LOWER_LIMIT);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_WARM_DATA_LOWER_LIMIT, size);
return ret;
}
} // namespace OHOS
@@ -20,13 +20,18 @@ ohos_fuzztest("HcWarmDataWaterLineFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hcwarmdatawaterline_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hcwarmdatawaterline_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
const char *HC_WARM_DATA_WATERLINE = "/sys/fs/f2fs/loop1/hc_warm_data_waterline";
namespace OHOS {
bool HcWarmDataWaterLineFuzzTest(const uint8_t *data, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_WARM_DATA_WATERLINE, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_WARM_DATA_WATERLINE);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_WARM_DATA_WATERLINE, size);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("HcWarmNodeLowerLimitFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hcwarmnodelowerlimit_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hcwarmnodelowerlimit_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -19,41 +19,15 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.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)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_WARM_NODE_LOWER_LIMIT, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_WARM_NODE_LOWER_LIMIT);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_WARM_NODE_LOWER_LIMIT, size);
return ret;
}
} // namespace OHOS
@@ -20,13 +20,18 @@ ohos_fuzztest("HcWarmNodeWaterLineFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "hcwarmnodewaterline_fuzzer.cpp" ]
sources = [
"../src/hccommon.cpp",
"hcwarmnodewaterline_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,47 +14,20 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.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)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(HC_WARM_NODE_WATERLINE, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", HC_WARM_NODE_WATERLINE);
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = HcFuzzTest(data, HC_WARM_NODE_WATERLINE, size);
return ret;
}
} // namespace OHOS
@@ -13,9 +13,11 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_SETTOKENIDCMDERROR_FUZZER_H
#define TEST_FUZZTEST_SETTOKENIDCMDERROR_FUZZER_H
#ifndef HCCOMMON_H
#define HCCOMMON_H
#define FUZZ_PROJECT_NAME "settokenidcmderror_fuzzer"
namespace OHOS {
bool HcFuzzTest(const uint8_t *data, const char *pathname, size_t size);
}
#endif // TEST_FUZZTEST_SETTOKENIDCMDERROR_FUZZER_H
#endif
+56
View File
@@ -0,0 +1,56 @@
/*
* 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 <cstddef>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "hccommon.h"
namespace OHOS {
bool HcFuzzTest(const uint8_t *data, const char *pathname, size_t size)
{
uint32_t value = 0;
uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size;
int ret = access("/mnt/f2fs_mount/", F_OK);
if (ret < 0) {
system("mkdir -p /mnt/f2fs_mount/");
system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs");
system("losetup /dev/block/loop1 /data/image_f2fs");
system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/");
}
int fd = open(pathname, O_RDWR);
if (fd < 0) {
return false;
}
ret = read(fd, &value, sizeof(value));
if (ret < 0) {
close(fd);
return false;
}
ret = write(fd, data, length);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
}
}
@@ -20,13 +20,18 @@ ohos_fuzztest("AnonRefaultSnapshotMinIntervalFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "anonrefaultsnapshotmininterval_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"anonrefaultsnapshotmininterval_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *ANON_REFAULT_SNAPSHOT_MIN_INTERVAL = "/dev/memcg/memory.anon_refault_snapshot_min_interval";
namespace OHOS {
bool AnonRefaultSnapshotMinIntervalFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(ANON_REFAULT_SNAPSHOT_MIN_INTERVAL, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", ANON_REFAULT_SNAPSHOT_MIN_INTERVAL);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, ANON_REFAULT_SNAPSHOT_MIN_INTERVAL);
return ret;
}
} // namespace OHOS
@@ -20,13 +20,18 @@ ohos_fuzztest("AppScoreFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/appscore_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "appscore_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"appscore_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *APP_SCORE = "/dev/memcg/memory.app_score";
namespace OHOS {
bool AppScoreFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(APP_SCORE, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", APP_SCORE);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, APP_SCORE);
return ret;
}
} // namespace OHOS
@@ -20,13 +20,18 @@ ohos_fuzztest("AreaAnonRefaultThresholdFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "areaanonrefaultthreshold_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"areaanonrefaultthreshold_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *AREA_ANON_REFAULT_THRESHOLD = "/dev/memcg/memory.area_anon_refault_threshold";
namespace OHOS {
bool AreaAnonRefaultThresholdFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(AREA_ANON_REFAULT_THRESHOLD, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", AREA_ANON_REFAULT_THRESHOLD);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, AREA_ANON_REFAULT_THRESHOLD);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("AvailBuffersFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/availbuffers_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "availbuffers_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"availbuffers_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *AVAIL_BUFFERS = "/dev/memcg/memory.avail_buffers";
namespace OHOS {
bool AvailBuffersFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(AVAIL_BUFFERS, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", AVAIL_BUFFERS);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, AVAIL_BUFFERS);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("BufferRatioParamsFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/bufferratioparams_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "bufferratioparams_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"bufferratioparams_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *BUFFER_RATIO_PARAMS = "/dev/memcg/memory.buffer_ratio_params";
namespace OHOS {
bool BufferRatioParamsFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(BUFFER_RATIO_PARAMS, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", BUFFER_RATIO_PARAMS);
close(fd);
return false;
}
ret = write(fd, data, sizeof(uint8_t));
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, BUFFER_RATIO_PARAMS);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("CompressRatioFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/compressratio_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "compressratio_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"compressratio_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *COMPRESS_RATIO = "/dev/memcg/memory.compress_ratio";
namespace OHOS {
bool CompressRatioFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(COMPRESS_RATIO, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", COMPRESS_RATIO);
close(fd);
return false;
}
ret = write(fd, data, sizeof(uint8_t));
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, COMPRESS_RATIO);
return ret;
}
} // namespace OHOS
@@ -20,13 +20,18 @@ ohos_fuzztest("EmptyRoundCheckThresholdFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "emptyroundcheckthreshold_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"emptyroundcheckthreshold_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *EMPTY_ROUND_CHECK_THRESHOLD = "/dev/memcg/memory.empty_round_check_threshold";
namespace OHOS {
bool EmptyRoundCheckThresholdFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(EMPTY_ROUND_CHECK_THRESHOLD, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", EMPTY_ROUND_CHECK_THRESHOLD);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, EMPTY_ROUND_CHECK_THRESHOLD);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("EmptyRoundSkipIntervalFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/emptyroundskipinterval_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "emptyroundskipinterval_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"emptyroundskipinterval_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *EMPTY_ROUND_SKIP_INTERVAL = "/dev/memcg/memory.empty_round_skip_interval";
namespace OHOS {
bool EmptyRoundSkipIntervalFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(EMPTY_ROUND_SKIP_INTERVAL, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", EMPTY_ROUND_SKIP_INTERVAL);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, EMPTY_ROUND_SKIP_INTERVAL);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("ForceShrinkAnonFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/forceshrinkanon_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "forceshrinkanon_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"forceshrinkanon_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,12 +14,11 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *FORCE_SHRINK_ANON = "/dev/memcg/memory.force_shrink_anon";
@@ -13,9 +13,11 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H
#define TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H
#ifndef MEMORYCOMMON_H
#define MEMORYCOMMON_H
#define FUZZ_PROJECT_NAME "gettokenidcmderror_fuzzer"
namespace OHOS {
bool MemoryFuzzTest(const uint8_t *data, size_t size, const char *pathname);
}
#endif // TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H
#endif
@@ -21,13 +21,18 @@ ohos_fuzztest("MaxSkipIntervalFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/maxskipinterval_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "maxskipinterval_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"maxskipinterval_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *MAX_SKIP_INTERVAL = "/dev/memcg/memory.max_skip_interval";
namespace OHOS {
bool MaxSkipIntervalFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(MAX_SKIP_INTERVAL, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", MAX_SKIP_INTERVAL);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, MAX_SKIP_INTERVAL);
return ret;
}
} // namespace OHOS
+6 -1
View File
@@ -20,13 +20,18 @@ ohos_fuzztest("NameFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/name_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "name_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"name_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *NAME = "/dev/memcg/memory.name";
namespace OHOS {
bool NameFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(NAME, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", NAME);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, NAME);
return ret;
}
} // namespace OHOS
@@ -13,9 +13,36 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H
#define TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H
#include <cstddef>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
#define FUZZ_PROJECT_NAME "getftokenidcmdcorrect_fuzzer"
namespace OHOS {
bool MemoryFuzzTest(const uint8_t *data, size_t size, const char *pathname)
{
uint32_t value = 0;
#endif // TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H
int fd = open(pathname, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
}
}
@@ -21,13 +21,18 @@ ohos_fuzztest("UbUfs2zramRatioFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/ubufs2zramratio_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "ubufs2zramratio_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"ubufs2zramratio_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *UB_UFS2ZRAM_RATIO = "/dev/memcg/memory.ub_ufs2zram_ratio";
namespace OHOS {
bool UbUfs2zramRatioFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(UB_UFS2ZRAM_RATIO, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", UB_UFS2ZRAM_RATIO);
close(fd);
return false;
}
ret = write(fd, data, sizeof(uint8_t));
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, UB_UFS2ZRAM_RATIO);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("ZramCriticalThresholdFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/zramcriticalthreshold_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "zramcriticalthreshold_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"zramcriticalthreshold_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *ZRAM_CRITICAL_THRESHOLD = "/dev/memcg/memory.zram_critical_threshold";
namespace OHOS {
bool ZramCriticalThresholdFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(ZRAM_CRITICAL_THRESHOLD, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", ZRAM_CRITICAL_THRESHOLD);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, ZRAM_CRITICAL_THRESHOLD);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("ZramWmRatioFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/zramwmratio_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "zramwmratio_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"zramwmratio_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *ZRAM_WR_RATIO = "/dev/memcg/memory.zram_wm_ratio";
namespace OHOS {
bool ZramWmRatioFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(ZRAM_WR_RATIO, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", ZRAM_WR_RATIO);
close(fd);
return false;
}
ret = write(fd, data, sizeof(uint8_t));
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, ZRAM_WR_RATIO);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("ZswapdMaxReclaimSizeFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "zswapdmaxreclaimsize_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"zswapdmaxreclaimsize_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *ZSWAPD_MAX_RECLAIM_SIZE = "/dev/memcg/memory.zswapd_max_reclaim_size";
namespace OHOS {
bool ZswapdMaxReclaimSizeFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(ZSWAPD_MAX_RECLAIM_SIZE, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", ZSWAPD_MAX_RECLAIM_SIZE);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, ZSWAPD_MAX_RECLAIM_SIZE);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("ZswapdMemcgsparamFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/zswapdmemcgsparam_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "zswapdmemcgsparam_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"zswapdmemcgsparam_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *ZSWAPD_MEMCGS_PARAM = "/dev/memcg/memory.zswapd_memcgs_param";
namespace OHOS {
bool ZswapdMemcgsParamFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(ZSWAPD_MEMCGS_PARAM, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", ZSWAPD_MEMCGS_PARAM);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, ZSWAPD_MEMCGS_PARAM);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("ZswapdPressureShowFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/zswapdpressureshow_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "zswapdpressureshow_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"zswapdpressureshow_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *ZSWAPD_PRESSURE_SHOW = "/dev/memcg/memory.zswapd_pressure_show";
namespace OHOS {
bool ZswapdPressureShowFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(ZSWAPD_PRESSURE_SHOW, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", ZSWAPD_PRESSURE_SHOW);
close(fd);
return false;
}
ret = write(fd, data, sizeof(uint8_t));
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, ZSWAPD_PRESSURE_SHOW);
return ret;
}
} // namespace OHOS
@@ -21,13 +21,18 @@ ohos_fuzztest("ZswapdSingleMemcgParamFuzzTest") {
fuzz_config_file =
"//kernel/linux/build/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer"
include_dirs = [ "../include" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "zswapdsinglememcgparam_fuzzer.cpp" ]
sources = [
"../src/memorycommon.cpp",
"zswapdsinglememcgparam_fuzzer.cpp",
]
}
group("fuzztest") {
@@ -14,40 +14,19 @@
*/
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include "memorycommon.h"
const char *ZSWAPD_SINGLE_MEMCG_PARAM = "/dev/memcg/memory.zswapd_single_memcg_param";
namespace OHOS {
bool ZswapdSingleMemcgParamFuzzer(const uint8_t *data, size_t size)
{
uint32_t value = 0;
int fd = open(ZSWAPD_SINGLE_MEMCG_PARAM, O_RDWR);
if (fd < 0) {
return false;
}
int ret = read(fd, &value, sizeof(value));
if (ret < 0) {
printf("%s read fail\n", ZSWAPD_SINGLE_MEMCG_PARAM);
close(fd);
return false;
}
ret = write(fd, data, size);
if (ret < 0) {
close(fd);
return false;
}
close(fd);
return true;
bool ret = MemoryFuzzTest(data, size, ZSWAPD_SINGLE_MEMCG_PARAM);
return ret;
}
} // namespace OHOS
@@ -14,6 +14,9 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#include "rtg_interface.h"
using namespace std;
@@ -14,6 +14,9 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#include "rtg_interface.h"
using namespace std;
@@ -14,6 +14,9 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#include "rtg_interface.h"
using namespace std;
@@ -14,6 +14,9 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#include "rtg_interface.h"
using namespace std;
@@ -14,6 +14,9 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#include "rtg_interface.h"
using namespace std;
@@ -14,6 +14,9 @@
*/
#include <vector>
#include <cstddef>
#include <cstdint>
#include "__config"
#include "rtg_interface.h"
using namespace std;