diff --git a/test/fuzztest/scanhelper_fuzzer/scanhelper_fuzzer.cpp b/test/fuzztest/scanhelper_fuzzer/scanhelper_fuzzer.cpp index 3bce3da..ac798e3 100644 --- a/test/fuzztest/scanhelper_fuzzer/scanhelper_fuzzer.cpp +++ b/test/fuzztest/scanhelper_fuzzer/scanhelper_fuzzer.cpp @@ -597,6 +597,124 @@ void TestScannerInfoTCPNapiInterface(const uint8_t* data, size_t size, FuzzedDat ScannerInfoHelperTCP::MakeJsObject(env, info); } +void TestSetNamedProperty(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value object = nullptr; + std::string name = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); + napi_value value = nullptr; + NapiScanUtils::SetNamedProperty(env, object, name, value); +} + +void TestGetUint32FromValue(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value value = nullptr; + NapiScanUtils::GetUint32FromValue(env, value); +} + +void TestGetInt32FromValue(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value value = nullptr; + NapiScanUtils::GetInt32FromValue(env, value); +} + +void TestGetStringFromValueUtf8(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value value = nullptr; + NapiScanUtils::GetStringFromValueUtf8(env, value); +} + +void TestValueIsArrayBuffer(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value value = nullptr; + NapiScanUtils::ValueIsArrayBuffer(env, value); +} + +void TestGetInfoFromArrayBufferValue(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value value = nullptr; + size_t *length = nullptr; + NapiScanUtils::GetInfoFromArrayBufferValue(env, value, length); +} + +void TestCreateObject(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + NapiScanUtils::CreateObject(env); +} + +void TestGetUndefined(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + NapiScanUtils::GetUndefined(env); +} + +void TestCallFunction(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value recv = nullptr; + napi_value func = nullptr; + size_t argc = 0; + napi_value *argv = nullptr; + NapiScanUtils::CallFunction(env, recv, func, argc, argv); +} + +void TestCreateReference(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value callback = nullptr; + NapiScanUtils::CreateReference(env, callback); +} + +void TestCreateBoolean(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + bool value = 1; + NapiScanUtils::CreateBoolean(env, value); +} + +void TestGetBooleanFromValue(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value value = nullptr; + NapiScanUtils::GetBooleanFromValue(env, value); +} + +void TestGetBooleanProperty(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value object = nullptr; + std::string propertyName = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); + NapiScanUtils::GetBooleanProperty(env, object, propertyName); +} + +void TestSetBooleanProperty(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value object = nullptr; + std::string name = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); + bool value = 1; + NapiScanUtils::SetBooleanProperty(env, object, name, value); +} + +void TestToLower(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + std::string s = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); + NapiScanUtils::ToLower(s); +} + +void TestGetValueString(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_value jsValue = nullptr; + NapiScanUtils::GetValueString(env, jsValue); +} + void TestGetExtensionIdInterface(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) { std::string globalId = dataProvider->ConsumeRandomLengthString(MAX_STRING_LENGTH); @@ -651,6 +769,15 @@ void TestIsPathValid(const uint8_t* data, size_t size, FuzzedDataProvider* dataP NapiScanUtils::IsPathValid(filePath); } +void TestGetJsVal(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) +{ + napi_env env = nullptr; + napi_callback_info info = nullptr; + napi_value* jsValue = nullptr; + size_t length = 1; + NapiScanUtils::GetJsVal(env, info, jsValue, length); +} + void ScanOptionDescriptorFuzzTest(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) { TestSetOptionName(data, size, dataProvider); @@ -762,6 +889,22 @@ void ScannerInfoHelperFuzzTest(const uint8_t* data, size_t size, FuzzedDataProvi void NapiScanUtilsFuzzTest(const uint8_t* data, size_t size, FuzzedDataProvider* dataProvider) { + TestSetNamedProperty(data, size, dataProvider); + TestGetUint32FromValue(data, size, dataProvider); + TestGetInt32FromValue(data, size, dataProvider); + TestGetStringFromValueUtf8(data, size, dataProvider); + TestValueIsArrayBuffer(data, size, dataProvider); + TestGetInfoFromArrayBufferValue(data, size, dataProvider); + TestCreateObject(data, size, dataProvider); + TestGetUndefined(data, size, dataProvider); + TestCallFunction(data, size, dataProvider); + TestCreateReference(data, size, dataProvider); + TestCreateBoolean(data, size, dataProvider); + TestGetBooleanFromValue(data, size, dataProvider); + TestGetBooleanProperty(data, size, dataProvider); + TestSetBooleanProperty(data, size, dataProvider); + TestToLower(data, size, dataProvider); + TestGetValueString(data, size, dataProvider); TestGetExtensionIdInterface(data, size, dataProvider); TestGetGlobalIdInterface(data, size, dataProvider); TestGetLocalIdInterface(data, size, dataProvider); @@ -770,6 +913,7 @@ void NapiScanUtilsFuzzTest(const uint8_t* data, size_t size, FuzzedDataProvider* TestGetTaskEventId(data, size, dataProvider); TestOpenFile(data, size, dataProvider); TestIsPathValid(data, size, dataProvider); + TestGetJsVal(data, size, dataProvider); } }