From 508919f1adb8eb51d424cf37ddfc71cb1ca34729 Mon Sep 17 00:00:00 2001 From: anton Date: Sun, 18 Feb 2024 20:17:48 +0000 Subject: [PATCH] Prevent ioctl(WSKBDIO_GETENCODINGS) NULL deference when sysctl machdep.forceukbd is enabled without any USB keyboard being attached. Found the hard way by sthen@; ok miod@ --- sys/dev/wscons/wskbd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/dev/wscons/wskbd.c b/sys/dev/wscons/wskbd.c index 7631cd5f701..f551bf5b892 100644 --- a/sys/dev/wscons/wskbd.c +++ b/sys/dev/wscons/wskbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wskbd.c,v 1.117 2023/11/23 15:02:57 deraadt Exp $ */ +/* $OpenBSD: wskbd.c,v 1.118 2024/02/18 20:17:48 anton Exp $ */ /* $NetBSD: wskbd.c,v 1.80 2005/05/04 01:52:16 augustss Exp $ */ /* @@ -1229,8 +1229,11 @@ getkeyrepeat: case WSKBDIO_GETENCODINGS: uedp = (struct wskbd_encoding_data *)data; - for (count = 0; sc->id->t_keymap.keydesc[count].name; count++) - ; + count = 0; + if (sc->id->t_keymap.keydesc != NULL) { + while (sc->id->t_keymap.keydesc[count].name) + count++; + } if (uedp->nencodings > count) uedp->nencodings = count; for (i = 0; i < uedp->nencodings; i++) { -- 2.20.1