Skip to content

Commit 95dffe3

Browse files
neosys007dtor
authored andcommitted
Input: aiptek - validate raw macro indices before updating state
aiptek_irq() derives macro key indices directly from tablet reports and then uses them to index macroKeyEvents[]. Report types 4 and 5 also save the derived value in aiptek->lastMacro and later use that state to release the previous key. Validate the raw macro index once before it enters that state machine, so lastMacro only ever stores an in-range macro key. Keep direct bounds checks for report type 6, which reads the macro number from the packet body and uses it immediately. Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Link: https://patch.msgid.link/20260329001711.88076-1-pengpeng@iscas.ac.cn [dtor: fix macro fallback in report 5s to use -1] Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent bc561dc commit 95dffe3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

drivers/input/tablet/aiptek.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ static void aiptek_irq(struct urb *urb)
657657
pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
658658

659659
macro = dv && p && tip && !(data[3] & 1) ? (data[3] >> 1) : -1;
660+
if (macro >= ARRAY_SIZE(macroKeyEvents))
661+
macro = -1;
660662
z = get_unaligned_le16(data + 4);
661663

662664
if (dv) {
@@ -698,7 +700,9 @@ static void aiptek_irq(struct urb *urb)
698700
left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
699701
right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
700702
middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
701-
macro = dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : 0;
703+
macro = dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : -1;
704+
if (macro >= ARRAY_SIZE(macroKeyEvents))
705+
macro = -1;
702706

703707
if (dv) {
704708
/* If the selected tool changed, reset the old
@@ -736,11 +740,11 @@ static void aiptek_irq(struct urb *urb)
736740
*/
737741
else if (data[0] == 6) {
738742
macro = get_unaligned_le16(data + 1);
739-
if (macro > 0) {
743+
if (macro > 0 && macro - 1 < ARRAY_SIZE(macroKeyEvents)) {
740744
input_report_key(inputdev, macroKeyEvents[macro - 1],
741745
0);
742746
}
743-
if (macro < 25) {
747+
if (macro + 1 < ARRAY_SIZE(macroKeyEvents)) {
744748
input_report_key(inputdev, macroKeyEvents[macro + 1],
745749
0);
746750
}
@@ -759,7 +763,8 @@ static void aiptek_irq(struct urb *urb)
759763
aiptek->curSetting.toolMode;
760764
}
761765

762-
input_report_key(inputdev, macroKeyEvents[macro], 1);
766+
if (macro < ARRAY_SIZE(macroKeyEvents))
767+
input_report_key(inputdev, macroKeyEvents[macro], 1);
763768
input_report_abs(inputdev, ABS_MISC,
764769
1 | AIPTEK_REPORT_TOOL_UNKNOWN);
765770
input_sync(inputdev);

0 commit comments

Comments
 (0)