Created attachment 204976 [details] Proposed patch There is a possible buffer overflow bug in sc_allocate_keyboard() of sys/dev/syscons/syscons.c. k0 = kbd_get_keyboard(idx0); for (idx = kbd_find_keyboard2("*", -1, 0); idx != -1; idx = kbd_find_keyboard2("*", -1, idx + 1)) { k = kbd_get_keyboard(idx); if (idx == idx0 || KBD_IS_BUSY(k)) continue; bzero(&ki, sizeof(ki)); strcpy(ki.kb_name, k->kb_name); ki.kb_unit = k->kb_unit; (void)kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki); } We should use strncpy to copy into a fixed-size buffer instead of strcpy(). The attachment is the proposed patch.
FWIW, it appears there is a similar issue at sys/dev/kbd/kbd.c:230 in function kbd_register(). Is there any downside to using a truncated name? Also, is there any reason not to use strlcpy()?
^Triage: clear stale flags. To submitter: is this aging PR still relevant?