Fix null pointer segfault in find_keyboard_device() - #2
Open
randytate wants to merge 1 commit into
Open
Conversation
test_dev was uninitialized when no device was found, causing libevdev_free() to be called on a garbage pointer. Initialize to NULL so libevdev_free(NULL) is safe.
|
Can confirm this does fix the issue. It doesn't detect my copilot button but it doesn't segfault anymore. |
Author
Yeah, it's working well for me ... using this LG Gram now. So glad I have a right-ctrl key again 'cause I use it for a lot of keyboard shortcuts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix null pointer segfault in find_keyboard_device() + meta suppression for correct RightCtrl mapping
Hardware & OS
Bug 1: Null pointer segfault in find_keyboard_device()
Problem
On Fedora 43, running
remap-copilotwithout a--deviceargument immediately segfaults:The coredump points to
libevdev_free()insidefind_keyboard_device():Root Cause
test_devis declared but never initialized infind_keyboard_device(). When neither scan loop finds a matching device and execution falls through tofind_keyboard_device_end,libevdev_free(test_dev)is called on an uninitialized pointer, causing the segfault.Fix
Initialize
test_devtoNULL.libevdev_free(NULL)is a safe no-op, correctly handling the no-device-found path.Bug 2: KEY_LEFTMETA and KEY_LEFTSHIFT leak through to the virtual device
Problem
Even after the null pointer fix, the Copilot key does not correctly behave as
RightCtrlfor key combinations. For example, pressing Copilot +=in Chrome does not zoom in. Monitoring the virtual uinput device withevtestreveals thatKEY_LEFTMETAandKEY_LEFTSHIFTare being passed through alongsideKEY_RIGHTCTRL:Applications see
Meta+Shift+RightCtrl+Equalinstead of the intendedRightCtrl+Equal, so shortcuts do not fire correctly.Root Cause
The existing code only suppresses
KEY_LEFTMETAandKEY_LEFTSHIFTpassthrough aftercopilot_activeis set — but by then both modifier keys have already been forwarded to the virtual device. The suppression is too late.Fix
Buffer
KEY_LEFTMETAon keydown rather than forwarding it immediately. IfKEY_F23follows (confirming a Copilot sequence), the buffered meta event is discarded. If meta is released without F23 — meaning it was a genuine Super key tap — the buffered down+up pair is flushed to the virtual device so normal Super key behavior (e.g. GNOME Activities) is preserved.KEY_LEFTSHIFTis suppressed whenevermeta_pressedis true, since shift only ever appears alongside meta as part of the Copilot chord.Testing
Verified on LG Gram Ultra 7 Series 2 (14Z90T-G.ADB6U1) running Fedora 43:
remap-copilot --listcorrectly enumerates input devices without crashingremap-copilot --verbosesuccessfully finds, grabs, and remaps the Copilot key on/dev/input/event3(AT Translated Set 2 keyboard)evteston the virtual uinput device confirms cleanKEY_RIGHTCTRLoutput with no meta/shift leakthrough=correctly zooms in Chromemake install-systemdNote: Bug 1 (null pointer) is self-contained and can be merged independently. Bug 2 (meta suppression) is included here as it is required for the tool to actually function correctly as a RightCtrl replacement on this hardware.