CristianHenzel / ClipIt

ClipIt clipboard manager for GTK+
https://github.com/CristianHenzel/ClipIt
GNU General Public License v3.0
653 stars 83 forks source link

Fix segmentation fault when special keys are pressed on history search #170

Closed jgidi closed 3 years ago

jgidi commented 3 years ago

Hello!

As pointed out by @ragnarov on issue #168, ClipIt crashes when the history shortcut is pressed and the history is already open. The crash actually happens whenever a special character such as Ctrl, Alt, Backspace or the arrow keys are pressed, since it causes the pointer match inside selected_from_input() to point to an empty char string. Then it propagates into undeline_match(), and causes a segmentation fault.

The program already performs a validity check for match inside selected_by_input() by using a conditional if (match) before calling underline_match(). However, it only catches the case when match is a null pointer.

This pull request is quite simple and consists in two commits. The first commit extends the validity check on selected_by_input() to ensure that match points to a non-empty char string, thus fixing all the related crash cases I could find while preserving the right character count for posterior key presses. The second commit removes a redundant if (match) included inside underline_match(), which is unnecessary since the function is only called after this condition is already ensured.

Cheers!

afelinczak commented 3 years ago

Thanks for the patch, looks good.