From be528c9559f3eb2065d8f91193a0f53792b05a9c Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Fri, 31 May 2024 18:03:58 +0800 Subject: [PATCH] Fix wrong testcases of AshmemFuzz and ThreadFuzz Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/I9U2YQ?from=project-issue Signed-off-by: chenkeyu --- base/test/fuzztest/ashmem_fuzzer/ashmem_fuzzer.cpp | 12 ++++-------- base/test/fuzztest/thread_fuzzer/thread_fuzzer.cpp | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/base/test/fuzztest/ashmem_fuzzer/ashmem_fuzzer.cpp b/base/test/fuzztest/ashmem_fuzzer/ashmem_fuzzer.cpp index 1c5e34b..62f2e7c 100644 --- a/base/test/fuzztest/ashmem_fuzzer/ashmem_fuzzer.cpp +++ b/base/test/fuzztest/ashmem_fuzzer/ashmem_fuzzer.cpp @@ -38,24 +38,20 @@ void AshmemTestFunc(FuzzedDataProvider* dataProvider) } string memoryContent = dataProvider->ConsumeRandomLengthString(MAX_MEMORY_SIZE); - ret = ashmem->WriteToAshmem(memoryContent.c_str(), sizeof(memoryContent), 0); + ret = ashmem->WriteToAshmem(memoryContent.c_str(), memoryContent.size(), 0); if (ret != true) { return; } string memoryContent2 = dataProvider->ConsumeRandomLengthString(MAX_MEMORY_SIZE); - ret = ashmem->WriteToAshmem(memoryContent2.c_str(), sizeof(memoryContent2), sizeof(memoryContent2)); + ret = ashmem->WriteToAshmem(memoryContent2.c_str(), memoryContent2.size(), memoryContent.size()); if (ret != true) { return; } - auto readData = ashmem->ReadFromAshmem(sizeof(memoryContent), 0); + ashmem->ReadFromAshmem(memoryContent.size(), 0); - const char *readContent = reinterpret_cast(readData); - - readData = ashmem->ReadFromAshmem(sizeof(memoryContent2), sizeof(memoryContent2)); - - readContent = reinterpret_cast(readData); + ashmem->ReadFromAshmem(memoryContent2.size(), memoryContent.size()); int prot = dataProvider->ConsumeIntegral(); ashmem->SetProtection(prot); diff --git a/base/test/fuzztest/thread_fuzzer/thread_fuzzer.cpp b/base/test/fuzztest/thread_fuzzer/thread_fuzzer.cpp index ddeef6a..5bd82e0 100644 --- a/base/test/fuzztest/thread_fuzzer/thread_fuzzer.cpp +++ b/base/test/fuzztest/thread_fuzzer/thread_fuzzer.cpp @@ -28,7 +28,7 @@ using namespace std; namespace OHOS { const std::string& DEFAULT_THREAD_NAME = "default"; -const int MAX_STACK_SIZE = 4096; +const int MAX_STACK_SIZE = 1024; const int MAX_PRIORITY = 10; using ThreadRunFunc = bool (*)(int& data); -- Gitee