Skip to content

Commit

Permalink
Merge pull request #115 from bhennion/pr/fixIOCTL
Browse files Browse the repository at this point in the history
Fix stack smashing due to mishandled ioctl bits reading
  • Loading branch information
dobey authored Sep 22, 2022
2 parents 19a763c + c787e02 commit 5b0d1a0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/mimhwkeyboardtracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void MImHwKeyboardTrackerPrivate::tryEvdevDevice(const char *device)
return;
}

if (ioctl(fd, EVIOCGBIT(0, EV_MAX), evbits) < 0) {
if (ioctl(fd, EVIOCGBIT(0, sizeof(evbits)), evbits) < 0) {
delete qfile;
return;
}
Expand All @@ -131,14 +131,14 @@ void MImHwKeyboardTrackerPrivate::tryEvdevDevice(const char *device)
return;
}

unsigned char swbit[BITS2BYTES(EV_MAX)];
if (ioctl(fd, EVIOCGBIT(EV_SW, SW_CNT), swbit) < 0) {
unsigned char swCapabilities[BITS2BYTES(SW_MAX)];
if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(swCapabilities)), swCapabilities) < 0) {
delete qfile;
return;
}

// Check that there is a tablet mode switch here
if (!TEST_BIT(SW_TABLET_MODE, swbit)) {
if (!TEST_BIT(SW_TABLET_MODE, swCapabilities)) {
delete qfile;
return;
}
Expand All @@ -152,11 +152,11 @@ void MImHwKeyboardTrackerPrivate::tryEvdevDevice(const char *device)
present = true;

// Initialise initial tablet mode state
unsigned long state[BITS2BYTES(SW_MAX)];
if (ioctl(fd, EVIOCGSW(SW_MAX), state) < 0)
unsigned char swState[BITS2BYTES(SW_MAX)];
if (ioctl(fd, EVIOCGSW(sizeof(swState)), swState) < 0)
return;

evdevTabletMode = TEST_BIT(SW_TABLET_MODE, state);
evdevTabletMode = TEST_BIT(SW_TABLET_MODE, swState);
}

MImHwKeyboardTrackerPrivate::~MImHwKeyboardTrackerPrivate()
Expand Down

0 comments on commit 5b0d1a0

Please sign in to comment.