Check if _direct_state_changed() argument is valid

- Modified classes: RigidBody, PhysicalBone, VehicleBody, RigidBody2D, KinematicBody2D
- The input argument is untrusted even in release mode

(cherry picked from commit e075b6b411)
This commit is contained in:
rafallus 2021-03-30 00:36:30 -06:00 committed by Rémi Verschelde
parent 7a6a150bc2
commit 3ab33d3ce9
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 6 additions and 19 deletions

View File

@ -440,12 +440,8 @@ bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia,
}
void RigidBody2D::_direct_state_changed(Object *p_state) {
#ifdef DEBUG_ENABLED
state = Object::cast_to<Physics2DDirectBodyState>(p_state);
#else
state = (Physics2DDirectBodyState *)p_state; //trust it
#endif
ERR_FAIL_COND_MSG(!state, "Method '_direct_state_changed' must receive a valid Physics2DDirectBodyState object as argument");
set_block_transform_notify(true); // don't want notify (would feedback loop)
if (mode != MODE_KINEMATIC)
@ -1437,11 +1433,11 @@ bool KinematicBody2D::is_sync_to_physics_enabled() const {
}
void KinematicBody2D::_direct_state_changed(Object *p_state) {
if (!sync_to_physics)
return;
Physics2DDirectBodyState *state = Object::cast_to<Physics2DDirectBodyState>(p_state);
ERR_FAIL_COND_MSG(!state, "Method '_direct_state_changed' must receive a valid Physics2DDirectBodyState object as argument");
last_valid_transform = state->get_transform();
set_notify_local_transform(false);

View File

@ -442,12 +442,8 @@ struct _RigidBodyInOut {
};
void RigidBody::_direct_state_changed(Object *p_state) {
#ifdef DEBUG_ENABLED
state = Object::cast_to<PhysicsDirectBodyState>(p_state);
#else
state = (PhysicsDirectBodyState *)p_state; //trust it
#endif
ERR_FAIL_COND_MSG(!state, "Method '_direct_state_changed' must receive a valid PhysicsDirectBodyState object as argument");
set_ignore_transform_notification(true);
set_global_transform(state->get_transform());
@ -2220,13 +2216,8 @@ void PhysicalBone::_direct_state_changed(Object *p_state) {
/// Update bone transform
PhysicsDirectBodyState *state;
#ifdef DEBUG_ENABLED
state = Object::cast_to<PhysicsDirectBodyState>(p_state);
#else
state = (PhysicsDirectBodyState *)p_state; //trust it
#endif
PhysicsDirectBodyState *state = Object::cast_to<PhysicsDirectBodyState>(p_state);
ERR_FAIL_COND_MSG(!state, "Method '_direct_state_changed' must receive a valid PhysicsDirectBodyState object as argument");
Transform global_transform(state->get_transform());

View File

@ -857,10 +857,10 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
}
void VehicleBody::_direct_state_changed(Object *p_state) {
RigidBody::_direct_state_changed(p_state);
state = Object::cast_to<PhysicsDirectBodyState>(p_state);
ERR_FAIL_COND_MSG(!state, "Method '_direct_state_changed' must receive a valid PhysicsDirectBodyState object as argument");
float step = state->get_step();