update test/fuzztest/storagetotalstatusservice_fuzzer/storagetotalstatusservice_fuzzer.cpp.

Signed-off-by: lixiyuan <lixiyuan7@huawei.com>
This commit is contained in:
lixiyuan 2024-11-21 07:13:11 +00:00 committed by Gitee
parent 1df4c33ed2
commit c139d4312f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -29,13 +29,14 @@ T TypeCast(const uint8_t *data, int *pos)
bool StorageTotalStatusServiceFuzzTest(const uint8_t *data, size_t size)
{
if ((data == nullptr) || (size == 0)) {
return false;
if ((data == nullptr) || (size < sizeof(uint64_t) * 3)) {
return true;
}
std::shared_ptr<StorageTotalStatusService> service = DelayedSingleton<StorageTotalStatusService>::GetInstance();
int64_t totalSize;
int64_t systemSize;
int64_t freeSize;
int64_t totalSize = TypeCast<int64_t>(data, nullptr);
int64_t systemSize = TypeCast<int64_t>(data + sizeof(int64_t), nullptr);
int64_t freeSize = TypeCast<int64_t>(data + sizeof(int64_t) * 2, nullptr);
int32_t result = service->GetTotalSize(totalSize);
if (result != E_OK) {
LOGI("Storage total status service fuzz test of interface StorageTotalStatusService::GetTotalSize failed!");