From 92376fa76c0b342f61d8b8505119bdf56d5af781 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 31 May 2018 02:57:51 +0000 Subject: [PATCH] Sanity check the return from the kernel. We should be getting back as many bytes as we asked for, and we don't handle shortages at all, so just reject anything that's not right. Differential Revision: https://reviews.freebsd.org/D15629 --- lib/libdevinfo/devinfo.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/libdevinfo/devinfo.c b/lib/libdevinfo/devinfo.c index 0666404785c8..49f7f0fbe5a4 100644 --- a/lib/libdevinfo/devinfo.c +++ b/lib/libdevinfo/devinfo.c @@ -220,6 +220,11 @@ devinfo_init_devices(int generation) warn("sysctl hw.bus.devices.%d", dev_idx); return(errno); } + if (rlen != sizeof(udev)) { + warnx("sysctl returned wrong data %zd bytes instead of %zd", + rlen, sizeof(udev)); + return (EINVAL); + } if ((dd = malloc(sizeof(*dd))) == NULL) return(ENOMEM); dd->dd_dev.dd_handle = udev.dv_handle;