diff --git a/frameworks/napi/input_event_client/include/js_register_util.h b/frameworks/napi/input_event_client/include/js_register_util.h index dd854820fa6047b27e1d82a1000f2e5d97e7a0b6..6804923c0f069bf4adc48ba4b820955c4f801f3e 100644 --- a/frameworks/napi/input_event_client/include/js_register_util.h +++ b/frameworks/napi/input_event_client/include/js_register_util.h @@ -30,6 +30,8 @@ bool IsArray(const napi_env& env, const napi_value& value); bool ParseInt32(const napi_env& env, const napi_value& value, int32_t& result); int32_t GetNamedPropertyArrayInt32(const napi_env& env, const napi_value& object, const std::string &name, std::vector& result); +int32_t GetNamedPropertyBoolOptional(const napi_env& env, const napi_value& object, const std::string& name, + bool& ret); } // namespace MMI } // namespace OHOS #endif // JS_REGISTER_UTIL_H \ No newline at end of file diff --git a/frameworks/napi/input_event_client/src/js_register_module.cpp b/frameworks/napi/input_event_client/src/js_register_module.cpp index 92028067f6ec19fdc66b0908311288d01f62850e..8482139e9278d12434809dbce8194a20cf9da093 100644 --- a/frameworks/napi/input_event_client/src/js_register_module.cpp +++ b/frameworks/napi/input_event_client/src/js_register_module.cpp @@ -372,11 +372,11 @@ static void HandleMousePropertyInt32(napi_env env, napi_value mouseHandle, THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "toolType must be greater than or equal to 0"); } int32_t globalX = INT_MAX; - if (GetNamedPropertyInt32(env, mouseHandle, "globalX", globalX) != RET_OK) { + if (GetNamedPropertyInt32(env, mouseHandle, "globalX", globalX, false) != RET_OK) { MMI_HILOGD("No globaX"); } int32_t globalY = INT_MAX; - if (GetNamedPropertyInt32(env, mouseHandle, "globalY", globalY) != RET_OK) { + if (GetNamedPropertyInt32(env, mouseHandle, "globalY", globalY, false) != RET_OK) { MMI_HILOGD("No globaY"); } pointerEvent->SetSourceType(toolType); @@ -426,7 +426,7 @@ static napi_value InjectMouseEvent(napi_env env, napi_callback_info info) return nullptr; } bool useGlobalCoordinate = false; - GetNamedPropertyBool(env, argv[0], "useGlobalCoordinate", useGlobalCoordinate); + GetNamedPropertyBoolOptional(env, argv[0], "useGlobalCoordinate", useGlobalCoordinate); auto pointerEvent = PointerEvent::Create(); PointerEvent::PointerItem item; CHKPP(pointerEvent); @@ -524,11 +524,11 @@ static void HandleTouchAttribute(napi_env env, std::shared_ptr poi MMI_HILOGE("Get pressure failed"); } int32_t globalX = INT_MAX; - if (GetNamedPropertyInt32(env, touchObject, "globalX", globalX) != RET_OK) { + if (GetNamedPropertyInt32(env, touchObject, "globalX", globalX, false) != RET_OK) { MMI_HILOGD("No globaX"); } int32_t globalY = INT_MAX; - if (GetNamedPropertyInt32(env, touchObject, "globalY", globalY) != RET_OK) { + if (GetNamedPropertyInt32(env, touchObject, "globalY", globalY, false) != RET_OK) { MMI_HILOGD("No globaY"); } @@ -660,7 +660,7 @@ static napi_value InjectTouchEvent(napi_env env, napi_callback_info info) return nullptr; } bool useGlobalCoordinate = false; - GetNamedPropertyBool(env, argv[0], "useGlobalCoordinate", useGlobalCoordinate); + GetNamedPropertyBoolOptional(env, argv[0], "useGlobalCoordinate", useGlobalCoordinate); auto pointerEvent = PointerEvent::Create(); PointerEvent::PointerItem item; CHKPP(pointerEvent); diff --git a/frameworks/napi/input_event_client/src/js_register_util.cpp b/frameworks/napi/input_event_client/src/js_register_util.cpp index c5ba30e101a8a7a1e11eee30e7d774d4f12beaa4..2a87db9a6a4f024d3781cca5e0df6ee3ed7ef248 100644 --- a/frameworks/napi/input_event_client/src/js_register_util.cpp +++ b/frameworks/napi/input_event_client/src/js_register_util.cpp @@ -204,5 +204,23 @@ int32_t GetNamedPropertyArrayInt32(const napi_env& env, const napi_value& object } return RET_OK; } + +int32_t GetNamedPropertyBoolOptional(const napi_env& env, const napi_value& object, const std::string& name, bool& ret) +{ + napi_value napiValue = {}; + CHKRF(napi_get_named_property(env, object, name.c_str(), &napiValue), GET_NAMED_PROPERTY); + if (napiValue == nullptr) { + MMI_HILOGE("The value is null"); + return RET_ERR; + } + napi_valuetype tmpType = napi_undefined; + CHKRF(napi_typeof(env, napiValue, &tmpType), TYPEOF); + if (tmpType != napi_boolean) { + MMI_HILOGE("The name:%{public}s is not bool", name.c_str()); + return RET_ERR; + } + CHKRF(napi_get_value_bool(env, napiValue, &ret), GET_VALUE_BOOL); + return RET_OK; +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/native/input/oh_input_manager.cpp b/frameworks/native/input/oh_input_manager.cpp index 43606fb76f84e2c00c7fe65303713fc9ab9fc1f5..8c8f4ca23074ccf33ca686dd94a2ff9db0f6e9f3 100644 --- a/frameworks/native/input/oh_input_manager.cpp +++ b/frameworks/native/input/oh_input_manager.cpp @@ -65,7 +65,7 @@ struct Input_TouchEvent { int32_t displayX; int32_t displayY; int32_t globalX { INT_MAX }; - int32_t globalY { INT_MAX };; + int32_t globalY { INT_MAX }; int64_t actionTime { -1 }; int32_t windowId { -1 }; int32_t displayId { -1 }; diff --git a/interfaces/native/innerkits/proxy/include/window_info.h b/interfaces/native/innerkits/proxy/include/window_info.h index 86116cb1dd9c3c3836afa92e417e757b650771ba..377c49f62b8b0a77a254c86db7dc7dfac62cb9bb 100644 --- a/interfaces/native/innerkits/proxy/include/window_info.h +++ b/interfaces/native/innerkits/proxy/include/window_info.h @@ -28,6 +28,7 @@ inline constexpr int32_t DEFAULT_GROUP_ID = 0; constexpr uint32_t MAX_DISPLAY_GROUP_SIZE = 100; constexpr uint32_t MAX_DISPLAY_SIZE = 1000; constexpr uint32_t MAX_SCREEN_SIZE = 1000; +constexpr uint32_t MAX_WINDOWS_SIZE = 1000; enum SecureFlag { DEFAULT_MODE = 0, diff --git a/service/message_handle/src/server_msg_handler.cpp b/service/message_handle/src/server_msg_handler.cpp index 9292de82b88ac46b08535bfff4d0f875b4f7ee7b..b2a3fd022e96ab817e02cc5d5ba6a28daf9a25d3 100644 --- a/service/message_handle/src/server_msg_handler.cpp +++ b/service/message_handle/src/server_msg_handler.cpp @@ -1017,6 +1017,10 @@ int32_t ServerMsgHandler::ReadWindowsInfo(NetPacket &pkt, DisplayGroupInfo &disp { uint32_t num = 0; pkt >> num; + if (num > MAX_WINDOWS_SIZE) { + MMI_HILOGE("Too many windows, num:%{public}u", num); + return RET_ERR; + } for (uint32_t i = 0; i < num; i++) { WindowInfo info; int32_t byteCount = 0;