Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check return value of sscanf to handle potential undefined behaviour in write_keymaps #147

Open
wants to merge 1 commit into
base: fedora-39
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions util/grub-mklayout.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,16 @@ write_keymaps (FILE *in, FILE *out, const char *out_filename)
char shift[64];
char normalalt[64];
char shiftalt[64];

sscanf (line, "keycode %u = %60s %60s %60s %60s", &keycode_linux,
normal, shift, normalalt, shiftalt);

if (sscanf (line, "keycode %u = %60s %60s %60s %60s", &keycode_linux,
normal, shift, normalalt, shiftalt) != 5) {
/* Bail out since keycodes could not be read, this can happen
* when the in FILE is coming from stdin and user fails to specify the keycode in
* proper format
*/
fprintf (stderr, "%s", _("ERROR: no valid keyboard layout found. Check the input.\n"));
exit (1);
}

if (keycode_linux >= ARRAY_SIZE (linux_to_usb_map))
{
Expand Down