From a9bb32cfe1ee87ff831707dfdcbcae56f2b2a036 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Fri, 5 Feb 2021 00:41:13 +0000 Subject: [PATCH] xf86drm: cap number of reported devices by drmGetDevice(2) Do as the documentation says - when devices non NULL, cap the reported devices to max_devices. Otherwise we risk out-of-bound access for users of the API. v2: - Fix this w/o breaking the API v3: - Drop local variables, flip inverted conditional (Simon) Issue: https://gitlab.freedesktop.org/mesa/drm/-/issues/56 Signed-off-by: Emil Velikov Reviewed-by: Simon Ser --- xf86drm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xf86drm.c b/xf86drm.c index dbb7c14b..0185e985 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -4272,6 +4272,10 @@ drm_public int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], } closedir(sysdir); + + if (devices != NULL) + return MIN2(device_count, max_devices); + return device_count; }