From 5c45258f03c2a1048f082481e57c7de5d6fc5c93 Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Fri, 8 Nov 2024 02:52:58 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfuzz=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cc_ggboy --- .../setosaccountprofilephoto_fuzzer.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/fuzztest/osaccount/setosaccountprofilephoto_fuzzer/setosaccountprofilephoto_fuzzer.cpp b/test/fuzztest/osaccount/setosaccountprofilephoto_fuzzer/setosaccountprofilephoto_fuzzer.cpp index efc2aa01e..16d438946 100644 --- a/test/fuzztest/osaccount/setosaccountprofilephoto_fuzzer/setosaccountprofilephoto_fuzzer.cpp +++ b/test/fuzztest/osaccount/setosaccountprofilephoto_fuzzer/setosaccountprofilephoto_fuzzer.cpp @@ -26,15 +26,25 @@ using namespace std; using namespace OHOS::AccountSA; const int LOCAL_ID = 100; +const uint8_t ARRAY_CHAR_SIZE = 62; +const char CHAR_ARRAY[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +static void GenerateRandStr(uint32_t len, const uint8_t *data, std::string& res) +{ + for (uint32_t i = 0; i < len; i++) { + uint32_t index = data[i] % ARRAY_CHAR_SIZE; + res.push_back(CHAR_ARRAY[index]); + } +} namespace OHOS { bool SetOsAccountProfilePhotoFuzzTest(const uint8_t* data, size_t size) { bool result = false; if ((data != nullptr) && (size != 0)) { - FuzzData fuzzData(data, size); - std::string testPhotoStr(fuzzData.GenerateRandomString()); - result = OsAccountManager::SetOsAccountProfilePhoto(LOCAL_ID, testPhotoStr); + std::string photo; + GenerateRandStr(size, data, photo); + result = OsAccountManager::SetOsAccountProfilePhoto(LOCAL_ID, photo); } return result; }