From 7f3ca66da83f58ac3a36cbd52278ac4cb0f97276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=89=E4=B8=9C?= Date: Tue, 5 Aug 2025 03:58:13 +0000 Subject: [PATCH 1/6] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张吉东 --- .../include/location_proxy_adapter_impl.h | 1 - .../src/sensor_adapter_impl.cpp | 19 ++++++++++++++----- .../include/ohos_adapter/location_adapter.h | 1 - .../sensoradapter_fuzz.cpp | 8 ++------ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h b/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h index 127267f06..34d22518a 100755 --- a/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h +++ b/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h @@ -17,7 +17,6 @@ #define LOCATION_PROXY_ADAPTER_IMPL_H #include -#include #if defined(NWEB_LOCATION_ENABLE) #include "i_locator_callback.h" diff --git a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp index 281462f15..4f93be1c3 100644 --- a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -24,7 +24,6 @@ namespace OHOS::NWeb { std::unordered_map> SensorAdapterImpl::sensorCallbackMap; std::mutex SensorAdapterImpl::sensorCallbackMapMutex_; - constexpr double NANOSECONDS_IN_SECOND = 1000000000.0; constexpr double DEFAULT_SAMPLE_PERIOD = 200000000.0; @@ -133,7 +132,7 @@ double SensorAdapterImpl::GetOhosSensorDefaultSupportedFrequency(int32_t sensorT defaultFrequency = NANOSECONDS_IN_SECOND / DEFAULT_SAMPLE_PERIOD; } WVLOG_I("GetOhosSensorDefaultSupportedFrequency sensorTypeId: %{public}d, defaultFrequency: %{public}f", - sensorTypeId, defaultFrequency); + sensorTypeId, defaultFrequency); return defaultFrequency; } @@ -162,7 +161,7 @@ double SensorAdapterImpl::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeI } } WVLOG_I("GetOhosSensorMinSupportedFrequency sensorTypeId: %{public}d, minFrequency: %{public}f", - sensorTypeId, minFrequency); + sensorTypeId, minFrequency); return minFrequency; } @@ -191,7 +190,7 @@ double SensorAdapterImpl::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeI } } WVLOG_I("GetOhosSensorMaxSupportedFrequency sensorTypeId: %{public}d, maxFrequency: %{public}f", - sensorTypeId, maxFrequency); + sensorTypeId, maxFrequency); return maxFrequency; } @@ -321,15 +320,19 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) case SENSOR_TYPE_ID_ACCELEROMETER: handleAccelerometerData(callback, event); break; + case SENSOR_TYPE_ID_GRAVITY: handleGravityData(callback, event); break; + case SENSOR_TYPE_ID_LINEAR_ACCELERATION: handleLinearAccelerometerData(callback, event); break; + case SENSOR_TYPE_ID_GYROSCOPE: handleCyroscopeData(callback, event); break; + case SENSOR_TYPE_ID_MAGNETIC_FIELD: handleMagnetometerData(callback, event); break; @@ -342,6 +345,7 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) case SENSOR_TYPE_ID_GAME_ROTATION_VECTOR: handleGameRotationVectorData(callback, event); break; + default: break; } @@ -349,6 +353,8 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) { + WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d, samplingInterval: %{public}ld", + sensorTypeId, samplingInterval); WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d", sensorTypeId); if (samplingInterval <= 0) { WVLOG_E("SubscribeOhosSensor error, samplingInterval is invalid."); @@ -361,7 +367,10 @@ int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t sam } std::string userName = SensorTypeToSensorUserName(sensorTypeId); - (void)strcpy_s(mSensorUser.name, sizeof(mSensorUser.name), userName.c_str()); + int cpyret = strcpy_s(mSensorUser.name, sizeof(mSensorUser.name), userName.c_str()); + if (cpyret != 0) { + WVLOG_E("SubscribeOhosSensor error, call strcpy_s ret = %{public}d.", cpyret); + } mSensorUser.userData = nullptr; mSensorUser.callback = &OhosSensorCallback; int32_t ret = SENSOR_SUCCESS; diff --git a/ohos_interface/include/ohos_adapter/location_adapter.h b/ohos_interface/include/ohos_adapter/location_adapter.h index 246b08c63..4b6c5a80a 100644 --- a/ohos_interface/include/ohos_adapter/location_adapter.h +++ b/ohos_interface/include/ohos_adapter/location_adapter.h @@ -19,7 +19,6 @@ #include #include #include -#include namespace OHOS::NWeb { diff --git a/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp b/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp index c8a43ea3c..8c7b783a9 100644 --- a/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp +++ b/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp @@ -62,15 +62,12 @@ bool SensorAdapterFuzzTest(const uint8_t* data, size_t size) sensorAdapterImpl.RegistOhosSensorCallback(sensorTypeId, callbackAdapter); SensorEvent event; event.sensorTypeId = sensorTypeId; - uint8_t *sensorData = 0; - event.data = sensorData; + event.data = nullptr; sensorAdapterImpl.OhosSensorCallback(&event); sensorAdapterImpl.UnsubscribeOhosSensor(sensorTypeId); - delete[] sensorData; } SensorEvent event; - uint8_t *sensorData = 0; - event.data = sensorData; + event.data = nullptr; sensorAdapterImpl.handleAccelerometerData(callback, &event); sensorAdapterImpl.handleLinearAccelerometerData(callback, &event); sensorAdapterImpl.handleGravityData(callback, &event); @@ -79,7 +76,6 @@ bool SensorAdapterFuzzTest(const uint8_t* data, size_t size) sensorAdapterImpl.handleOrientationData(callback, &event); sensorAdapterImpl.handleRotationVectorData(callback, &event); sensorAdapterImpl.handleGameRotationVectorData(callback, &event); - delete[] sensorData; return true; } } // namespace NWeb -- Gitee From 54e1bf0484b1272034550dcb0b4e1ed07a3af7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=89=E4=B8=9C?= Date: Tue, 5 Aug 2025 06:35:06 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张吉东 --- .../location_adapter/include/location_proxy_adapter_impl.h | 1 + ohos_interface/include/ohos_adapter/location_adapter.h | 1 + 2 files changed, 2 insertions(+) diff --git a/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h b/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h index 34d22518a..127267f06 100755 --- a/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h +++ b/ohos_adapter/location_adapter/include/location_proxy_adapter_impl.h @@ -17,6 +17,7 @@ #define LOCATION_PROXY_ADAPTER_IMPL_H #include +#include #if defined(NWEB_LOCATION_ENABLE) #include "i_locator_callback.h" diff --git a/ohos_interface/include/ohos_adapter/location_adapter.h b/ohos_interface/include/ohos_adapter/location_adapter.h index 4b6c5a80a..246b08c63 100644 --- a/ohos_interface/include/ohos_adapter/location_adapter.h +++ b/ohos_interface/include/ohos_adapter/location_adapter.h @@ -19,6 +19,7 @@ #include #include #include +#include namespace OHOS::NWeb { -- Gitee From 93303f2559d7079dad22dda6f93223c3109e9cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=89=E4=B8=9C?= Date: Wed, 6 Aug 2025 03:52:43 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0ld=E4=B8=BAlld?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张吉东 --- ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp index 4f93be1c3..a6db2408d 100644 --- a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -353,7 +353,7 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) { - WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d, samplingInterval: %{public}ld", + WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d, samplingInterval: %{public}lld", sensorTypeId, samplingInterval); WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d", sensorTypeId); if (samplingInterval <= 0) { -- Gitee From c36262d5f22de20d42cbeae390aef3e4bcf1b008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=89=E4=B8=9C?= Date: Wed, 6 Aug 2025 07:20:27 +0000 Subject: [PATCH 4/6] =?UTF-8?q?%lld=E7=BB=9F=E4=B8=80=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BAPRId64=E5=AE=8F=EF=BC=8C=E5=86=97=E4=BD=99=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=88=A0=E9=99=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张吉东 --- ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp index a6db2408d..591be504a 100644 --- a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -15,6 +15,7 @@ #include "sensor_adapter_impl.h" +#include #include #include @@ -353,9 +354,8 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) { - WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d, samplingInterval: %{public}lld", + WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d, samplingInterval: %{public}" PRId64, sensorTypeId, samplingInterval); - WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d", sensorTypeId); if (samplingInterval <= 0) { WVLOG_E("SubscribeOhosSensor error, samplingInterval is invalid."); return SENSOR_PARAMETER_ERROR; -- Gitee From cc252766f085577a2ccd8ed3b5876ebbc5be38dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=89=E4=B8=9C?= Date: Wed, 6 Aug 2025 09:08:01 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E5=A4=B4=E6=96=87=E4=BB=B6=E4=BD=BF=E7=94=A8cinttypes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张吉东 --- ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp index 591be504a..138cf2c07 100644 --- a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -15,7 +15,7 @@ #include "sensor_adapter_impl.h" -#include +#include #include #include -- Gitee From 1d049a90740502da8175517bf9e830f0df7bd7c8 Mon Sep 17 00:00:00 2001 From: wangshengwen333 Date: Thu, 7 Aug 2025 10:06:22 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=8F=8C=E9=87=8D?= =?UTF-8?q?=E6=8C=87=E9=92=88=E5=88=A4=E7=A9=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangshengwen333 --- .../src/ohos_native_buffer_adapter_impl.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp b/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp index fb01ac4d8..1ac6f0e59 100644 --- a/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp +++ b/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp @@ -82,6 +82,10 @@ int OhosNativeBufferAdapterImpl::GetEGLBuffer(void* buffer, void** eglBuffer) WVLOG_E("native buffer get egl buffer, buffer is null."); return -1; } + if (eglBuffer == nullptr) { + WVLOG_E("native buffer get egl buffer, eglBuffer pointer is null."); + return -1; + } WVLOG_D("native buffer GetEGLBuffer %{private}p.", buffer); OHNativeWindowBuffer* nativeWindowBuffer = @@ -115,6 +119,11 @@ int OhosNativeBufferAdapterImpl::NativeBufferFromNativeWindowBuffer(void* native return -1; } + if (nativeBuffer == nullptr) { + WVLOG_E("output nativeBuffer pointer is null"); + return -1; + } + *nativeBuffer = OH_NativeBufferFromNativeWindowBuffer(static_cast(nativeWindowBuffer)); if (*nativeBuffer == nullptr) { WVLOG_E("native buffer NativeBufferFromNativeWindowBuffer, native buffer is null."); @@ -140,6 +149,10 @@ void OhosNativeBufferAdapterImpl::Allocate( if (bufferConfig == nullptr) { return; } + if (outBuffer == nullptr) { + WVLOG_E("Output buffer pointer is null"); + return; + } int width = bufferConfig->GetBufferWidth(); int height = bufferConfig->GetBufferHeight(); int usage = bufferConfig->GetBufferUsage(); @@ -190,6 +203,11 @@ int OhosNativeBufferAdapterImpl::Lock(void* buffer, uint64_t usage, int32_t fenc return -1; } + if (out_virtual_address == nullptr) { + WVLOG_E("output address pointer is null."); + return -1; + } + if (IsBufferLocked(static_cast(buffer))) { WVLOG_D("native buffer lock - buffer already locked."); return -1; -- Gitee