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 23567b743504ed139eae15fc1fed106999041c11..64eb3c64036e06ef9463df4a70d92b3161ca4c2b --- 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 4a00b26de7cbb9e285c8e7e744f4febc4d72bc99..faebb5ad39ee64a4a33d6223de1142f9f2b579b4 100644 --- a/interfaces/plugin/vibrator/src/vibrator_js.cpp +++ b/interfaces/plugin/vibrator/src/vibrator_js.cpp @@ -53,11 +53,19 @@ 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__); + 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; } - char *vibratorEffect = (char *)malloc((bufLength + 1) * sizeof(char)); status = napi_get_value_string_utf8(env, args[0], vibratorEffect, bufLength + 1, &bufLength); asyncCallbackInfo->error.code = StartVibrator(vibratorEffect); if (vibratorEffect != nullptr) { @@ -105,11 +113,19 @@ 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__); + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; + return nullptr; + } + char *mode = static_cast(malloc((bufLength + 1) * sizeof(char))); + if (mode == nullptr) { + HiLog::Error(LABEL, "%{public}s malloc fail", __func__); + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return nullptr; } - char *mode = (char *)malloc((bufLength + 1) * sizeof(char)); status = napi_get_value_string_utf8(env, args[0], mode, bufLength + 1, &bufLength); asyncCallbackInfo->error.code = StopVibrator(mode); if (mode != nullptr) {