Skip to content

Commit 56f5ad2

Browse files
author
Akhilesh Sanikop
committed
inputflinger: Restricted invalid InputDeviceClass enum values
Updated FuzzEventHub::getDeviceClasses() to avoid returning invalid InputDeviceClass enum values. Added IfThisThenThat Lint to remind the InputClassDevices enum to sync Test: ./inputflinger_keyboard_input_fuzzer Bug: 351972616 Flag: EXEMPT bugfix in fuzzer Change-Id: I23fa0e501714c8a6029d132934293c1884950a7e
1 parent 01f7c33 commit 56f5ad2

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

services/inputflinger/reader/include/EventHub.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ std::ostream& operator<<(std::ostream& out, const std::optional<RawAbsoluteAxisI
8888
* If any new classes are added, we need to add them in rust input side too.
8989
*/
9090
enum class InputDeviceClass : uint32_t {
91+
// LINT.IfChange
9192
/* The input device is a keyboard or has buttons. */
9293
KEYBOARD = android::os::IInputConstants::DEVICE_CLASS_KEYBOARD,
9394

@@ -144,6 +145,7 @@ enum class InputDeviceClass : uint32_t {
144145

145146
/* The input device is external (not built-in). */
146147
EXTERNAL = android::os::IInputConstants::DEVICE_CLASS_EXTERNAL,
148+
// LINT.ThenChange(frameworks/native/services/inputflinger/tests/fuzzers/MapperHelpers.h)
147149
};
148150

149151
enum class SysfsClass : uint32_t {

services/inputflinger/tests/fuzzers/MapperHelpers.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ constexpr size_t kValidTypes[] = {EV_SW,
3434
android::EventHubInterface::DEVICE_ADDED,
3535
android::EventHubInterface::DEVICE_REMOVED};
3636

37+
static const android::InputDeviceClass kInputDeviceClasses[] = {
38+
android::InputDeviceClass::KEYBOARD,
39+
android::InputDeviceClass::ALPHAKEY,
40+
android::InputDeviceClass::TOUCH,
41+
android::InputDeviceClass::CURSOR,
42+
android::InputDeviceClass::TOUCH_MT,
43+
android::InputDeviceClass::DPAD,
44+
android::InputDeviceClass::GAMEPAD,
45+
android::InputDeviceClass::SWITCH,
46+
android::InputDeviceClass::JOYSTICK,
47+
android::InputDeviceClass::VIBRATOR,
48+
android::InputDeviceClass::MIC,
49+
android::InputDeviceClass::EXTERNAL_STYLUS,
50+
android::InputDeviceClass::ROTARY_ENCODER,
51+
android::InputDeviceClass::SENSOR,
52+
android::InputDeviceClass::BATTERY,
53+
android::InputDeviceClass::LIGHT,
54+
android::InputDeviceClass::TOUCHPAD,
55+
android::InputDeviceClass::VIRTUAL,
56+
android::InputDeviceClass::EXTERNAL,
57+
};
58+
3759
constexpr size_t kValidCodes[] = {
3860
SYN_REPORT,
3961
ABS_MT_SLOT,
@@ -105,7 +127,13 @@ class FuzzEventHub : public EventHubInterface {
105127
void addProperty(std::string key, std::string value) { mFuzzConfig.addProperty(key, value); }
106128

107129
ftl::Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const override {
108-
return ftl::Flags<InputDeviceClass>(mFdp->ConsumeIntegral<uint32_t>());
130+
uint32_t flags = 0;
131+
for (auto inputDeviceClass : kInputDeviceClasses) {
132+
if (mFdp->ConsumeBool()) {
133+
flags |= static_cast<uint32_t>(inputDeviceClass);
134+
}
135+
}
136+
return ftl::Flags<InputDeviceClass>(flags);
109137
}
110138
InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const override {
111139
return mIdentifier;

0 commit comments

Comments
 (0)