Bug 1488573 - Part 2: Checking OpenVR btn/axis count at runtime to avoid array overflow. r=kip

MozReview-Commit-ID: 5KgcuAcKCmO

Differential Revision: https://phabricator.services.mozilla.com/D6744

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daosheng Mu 2018-09-25 22:00:30 +00:00
Родитель ab575da60d
Коммит e807dc8d6a
2 изменённых файлов: 83 добавлений и 38 удалений

Просмотреть файл

@ -797,16 +797,25 @@ VRSystemManagerOpenVR::HandleInput()
buttonIdx = (buttonIdx == 0) ? 4 : 0;
}
HandleAxisMove(i, axisIdx,
state.rAxis[j].x);
if (!HandleAxisMove(i, axisIdx, state.rAxis[j].x)) {
RemoveControllers();
return;
}
++axisIdx;
HandleAxisMove(i, axisIdx,
state.rAxis[j].y * yAxisInvert);
if (!HandleAxisMove(i, axisIdx, state.rAxis[j].y * yAxisInvert)) {
RemoveControllers();
return;
}
++axisIdx;
HandleButtonPress(i, buttonIdx,
::vr::ButtonMaskFromId(
static_cast<::vr::EVRButtonId>(::vr::k_EButton_Axis0 + j)),
state.ulButtonPressed, state.ulButtonTouched);
if (!HandleButtonPress(i, buttonIdx,
::vr::ButtonMaskFromId(
static_cast<::vr::EVRButtonId>(::vr::k_EButton_Axis0 + j)),
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
if (mIsWindowsMR) {
@ -816,15 +825,24 @@ VRSystemManagerOpenVR::HandleInput()
break;
case vr::EVRControllerAxisType::k_eControllerAxis_Trigger:
if (j <= 2) {
HandleTriggerPress(i, buttonIdx, triggerIdx, state.rAxis[j].x);
if (!HandleTriggerPress(i, buttonIdx, triggerIdx, state.rAxis[j].x)) {
RemoveControllers();
return;
}
++buttonIdx;
++triggerIdx;
} else {
// For SteamVR Knuckles.
HandleTriggerPress(i, buttonIdx, triggerIdx, state.rAxis[j].x);
if (!HandleTriggerPress(i, buttonIdx, triggerIdx, state.rAxis[j].x)) {
RemoveControllers();
return;
}
++buttonIdx;
++triggerIdx;
HandleTriggerPress(i, buttonIdx, triggerIdx, state.rAxis[j].y);
if (!HandleTriggerPress(i, buttonIdx, triggerIdx, state.rAxis[j].y)) {
RemoveControllers();
return;
}
++buttonIdx;
++triggerIdx;
}
@ -838,23 +856,32 @@ VRSystemManagerOpenVR::HandleInput()
trackedIndex, ::vr::Prop_SupportedButtons_Uint64);
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_A)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_A),
state.ulButtonPressed, state.ulButtonTouched);
if (!HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_A),
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_Grip)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_Grip),
state.ulButtonPressed, state.ulButtonTouched);
if (!HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_Grip),
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_ApplicationMenu)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_ApplicationMenu),
state.ulButtonPressed, state.ulButtonTouched);
if (!HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_ApplicationMenu),
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
}
if (mIsWindowsMR) {
@ -864,30 +891,42 @@ VRSystemManagerOpenVR::HandleInput()
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Left)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Left),
state.ulButtonPressed, state.ulButtonTouched);
if (!HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Left),
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Up)) {
HandleButtonPress(i, buttonIdx,
if (!HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Up),
state.ulButtonPressed, state.ulButtonTouched);
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Right)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Right),
state.ulButtonPressed, state.ulButtonTouched);
if (!HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Right),
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
}
if (supportedButtons &
BTN_MASK_FROM_ID(k_EButton_DPad_Down)) {
HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Down),
state.ulButtonPressed, state.ulButtonTouched);
if (!HandleButtonPress(i, buttonIdx,
BTN_MASK_FROM_ID(k_EButton_DPad_Down),
state.ulButtonPressed, state.ulButtonTouched)) {
RemoveControllers();
return;
}
++buttonIdx;
}
MOZ_ASSERT(buttonIdx ==
@ -941,7 +980,7 @@ VRSystemManagerOpenVR::HandleInput()
}
}
void
bool
VRSystemManagerOpenVR::HandleButtonPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
@ -954,7 +993,7 @@ VRSystemManagerOpenVR::HandleButtonPress(uint32_t aControllerIdx,
const uint64_t touchedDiff = (controller->GetButtonTouched() ^ aButtonTouched);
if (!pressedDiff && !touchedDiff) {
return;
return true;
}
if (pressedDiff & aButtonMask ||
@ -968,14 +1007,16 @@ VRSystemManagerOpenVR::HandleButtonPress(uint32_t aControllerIdx,
aButton,
controller->GetControllerInfo().GetNumButtons(),
controller->GetControllerInfo().GetControllerName());
return false;
}
NewButtonEvent(aControllerIdx, aButton, aButtonMask & aButtonPressed,
aButtonMask & aButtonTouched,
(aButtonMask & aButtonPressed) ? 1.0L : 0.0L);
}
return true;
}
void
bool
VRSystemManagerOpenVR::HandleTriggerPress(uint32_t aControllerIdx,
uint32_t aButton,
uint32_t aTrigger,
@ -998,14 +1039,16 @@ VRSystemManagerOpenVR::HandleTriggerPress(uint32_t aControllerIdx,
aButton,
controller->GetControllerInfo().GetNumButtons(),
controller->GetControllerInfo().GetControllerName());
return false;
}
NewButtonEvent(aControllerIdx, aButton, aValue > threshold,
aValue > threshold, aValue);
controller->SetTrigger(aTrigger, aValue);
}
return true;
}
void
bool
VRSystemManagerOpenVR::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
float aValue)
{
@ -1019,10 +1062,12 @@ VRSystemManagerOpenVR::HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
aAxis,
controller->GetControllerInfo().GetNumAxes(),
controller->GetControllerInfo().GetControllerName());
return false;
}
NewAxisMove(aControllerIdx, aAxis, aValue);
controller->SetAxisMove(aAxis, aValue);
}
return true;
}
void

Просмотреть файл

@ -146,16 +146,16 @@ protected:
VRSystemManagerOpenVR();
private:
void HandleButtonPress(uint32_t aControllerIdx,
bool HandleButtonPress(uint32_t aControllerIdx,
uint32_t aButton,
uint64_t aButtonMask,
uint64_t aButtonPressed,
uint64_t aButtonTouched);
void HandleTriggerPress(uint32_t aControllerIdx,
bool HandleTriggerPress(uint32_t aControllerIdx,
uint32_t aButton,
uint32_t aTrigger,
float aValue);
void HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
bool HandleAxisMove(uint32_t aControllerIdx, uint32_t aAxis,
float aValue);
void HandlePoseTracking(uint32_t aControllerIdx,
const dom::GamepadPoseState& aPose,