!2249 修复fuzz用例

Merge pull request !2249 from cc_ggboy/master
This commit is contained in:
openharmony_ci 2024-11-08 06:23:24 +00:00 committed by Gitee
commit 3dd4b95ad5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -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;
}