> Date: Wed, 9 Oct 2024 16:23:11 +0200 > From: Alexander Bluhm <bl...@openbsd.org> > > On Tue, Oct 08, 2024 at 06:29:19PM +0000, Miod Vallat wrote: > > > So it happens here: > > > > > > 1010 int > > > 1011 wsdisplaywrite(dev_t dev, struct uio *uio, int flag) > > > 1012 { > > > 1013 struct wsdisplay_softc *sc; > > > 1014 struct tty *tp; > > > 1015 int unit; > > > 1016 struct wsscreen *scr; > > > 1017 > > > 1018 unit = WSDISPLAYUNIT(dev); > > > * 1019 sc = wsdisplay_cd.cd_devs[unit]; > > > > This would imply no wsdisplay device has attached, yet wscons has > > claimed console (either efifb or a vga-compatible display). > > Would it make sense to copy the check from wsdisplayopen() > instead of crashing in this case?
Not sure. We shouldn't be able to get here without passing the check in wsdisplayopen() under normal corcumstances. > Or should we prevent that situation on higher level? Yes, but it is not clear what we should do. Presumably one of the calls in wscn_video_init() succeeds, but then later on we don't actually attach the corresponding device. > Index: dev/wscons/wsdisplay.c > =================================================================== > RCS file: /data/mirror/openbsd/cvs/src/sys/dev/wscons/wsdisplay.c,v > diff -u -p -r1.153 wsdisplay.c > --- dev/wscons/wsdisplay.c 30 Sep 2024 01:41:49 -0000 1.153 > +++ dev/wscons/wsdisplay.c 9 Oct 2024 14:17:30 -0000 > @@ -1016,7 +1016,9 @@ wsdisplaywrite(dev_t dev, struct uio *ui > struct wsscreen *scr; > > unit = WSDISPLAYUNIT(dev); > - sc = wsdisplay_cd.cd_devs[unit]; > + if (unit >= wsdisplay_cd.cd_ndevs || /* make sure it was attached */ > + (sc = wsdisplay_cd.cd_devs[unit]) == NULL) > + return (ENXIO); > > if (ISWSDISPLAYCTL(dev)) > return (0); > >