From 4c9786d22a4452f2462b5acc293d9fc17363c877 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Tue, 22 Mar 2022 16:35:33 +0800 Subject: [PATCH 1/2] modify kora warning Signed-off-by: hellohyh001 --- .../miscdevice/src/miscdevice_service_proxy.cpp | 8 ++++++++ interfaces/plugin/vibrator/src/vibrator_js.cpp | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) mode change 100755 => 100644 frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp diff --git a/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp b/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp old mode 100755 new mode 100644 index 23567b7..64eb3c6 --- a/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp +++ b/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp @@ -95,6 +95,10 @@ std::vector MiscdeviceServiceProxy::GetVibratorIdList() return idVec; } uint32_t setCount = reply.ReadUint32(); + if (setCount <= 0 || setCount > idVec.max_size()) { + HiLog::Error(LABEL, "%{public}s setCount: %{public}d is invalid", __func__, setCount); + return idVec; + } idVec.resize(setCount); reply.ReadInt32Vector(&idVec); return idVec; @@ -301,6 +305,10 @@ std::vector MiscdeviceServiceProxy::GetLightSupportId() HiLog::Error(LABEL, "%{public}s failed, ret : %{public}d", __func__, ret); } int32_t setCount = reply.ReadInt32(); + if (setCount <= 0 || setCount > idVec.max_size()) { + HiLog::Error(LABEL, "%{public}s setCount: %{public}d is invalid", __func__, setCount); + return idVec; + } idVec.resize(setCount); reply.ReadInt32Vector(&idVec); return idVec; diff --git a/interfaces/plugin/vibrator/src/vibrator_js.cpp b/interfaces/plugin/vibrator/src/vibrator_js.cpp index 4a00b26..991a2e0 100644 --- a/interfaces/plugin/vibrator/src/vibrator_js.cpp +++ b/interfaces/plugin/vibrator/src/vibrator_js.cpp @@ -53,11 +53,15 @@ static napi_value Vibrate(napi_env env, napi_callback_info info) } else if (IsMatchType(args[0], napi_string, env)) { size_t bufLength = 0; napi_status status = napi_get_value_string_utf8(env, args[0], nullptr, 0, &bufLength); - if (bufLength < 0) { + if (status != napi_ok) { HiLog::Error(LABEL, "%{public}s input parameter is invalid", __func__); return nullptr; } - char *vibratorEffect = (char *)malloc((bufLength + 1) * sizeof(char)); + char *vibratorEffect = static_cast(malloc((bufLength + 1) * sizeof(char))); + if (vibratorEffect == nullptr) { + HiLog::Error(LABEL, "%{public}s malloc fail", __func__); + return nullptr; + } status = napi_get_value_string_utf8(env, args[0], vibratorEffect, bufLength + 1, &bufLength); asyncCallbackInfo->error.code = StartVibrator(vibratorEffect); if (vibratorEffect != nullptr) { @@ -105,11 +109,15 @@ static napi_value Stop(napi_env env, napi_callback_info info) }; size_t bufLength = 0; napi_status status = napi_get_value_string_utf8(env, args[0], nullptr, 0, &bufLength); - if (bufLength < 0) { + if (status != napi_ok) { HiLog::Error(LABEL, "%{public}s input parameter is invalid", __func__); return nullptr; } - char *mode = (char *)malloc((bufLength + 1) * sizeof(char)); + char *mode = static_cast(malloc((bufLength + 1) * sizeof(char))); + if (mode == 0) { + HiLog::Error(LABEL, "%{public}s malloc fail", __func__); + return nullptr; + } status = napi_get_value_string_utf8(env, args[0], mode, bufLength + 1, &bufLength); asyncCallbackInfo->error.code = StopVibrator(mode); if (mode != nullptr) { -- Gitee From 909a82e7da4a1dc86f5c910cead597e2d3e2662b Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Tue, 22 Mar 2022 17:36:09 +0800 Subject: [PATCH 2/2] modify kora warning Signed-off-by: hellohyh001 --- interfaces/plugin/vibrator/src/vibrator_js.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/interfaces/plugin/vibrator/src/vibrator_js.cpp b/interfaces/plugin/vibrator/src/vibrator_js.cpp index 991a2e0..faebb5a 100644 --- a/interfaces/plugin/vibrator/src/vibrator_js.cpp +++ b/interfaces/plugin/vibrator/src/vibrator_js.cpp @@ -55,11 +55,15 @@ static napi_value Vibrate(napi_env env, napi_callback_info info) napi_status status = napi_get_value_string_utf8(env, args[0], nullptr, 0, &bufLength); if (status != napi_ok) { HiLog::Error(LABEL, "%{public}s input parameter is invalid", __func__); + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return nullptr; } char *vibratorEffect = static_cast(malloc((bufLength + 1) * sizeof(char))); if (vibratorEffect == nullptr) { HiLog::Error(LABEL, "%{public}s malloc fail", __func__); + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return nullptr; } status = napi_get_value_string_utf8(env, args[0], vibratorEffect, bufLength + 1, &bufLength); @@ -111,11 +115,15 @@ static napi_value Stop(napi_env env, napi_callback_info info) napi_status status = napi_get_value_string_utf8(env, args[0], nullptr, 0, &bufLength); if (status != napi_ok) { HiLog::Error(LABEL, "%{public}s input parameter is invalid", __func__); + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return nullptr; } char *mode = static_cast(malloc((bufLength + 1) * sizeof(char))); - if (mode == 0) { + if (mode == nullptr) { HiLog::Error(LABEL, "%{public}s malloc fail", __func__); + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return nullptr; } status = napi_get_value_string_utf8(env, args[0], mode, bufLength + 1, &bufLength); -- Gitee