xf86drm: cap number of reported devices by drmGetDevice(2)

Do as the documentation says - cap the number of reported devices to the
requested amount - aka max_devices. Otherwise we risk out-of-bound access
for users of the API.

Issue: https://gitlab.freedesktop.org/mesa/drm/-/issues/56
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
main
Emil Velikov 2021-02-05 00:41:13 +00:00
parent 19f0a9cb87
commit 8cb12a2528
1 changed files with 4 additions and 3 deletions

View File

@ -4263,12 +4263,13 @@ drm_public int drmGetDevices2(uint32_t flags, drmDevicePtr devices[],
if (!local_devices[i]) if (!local_devices[i])
continue; continue;
if ((devices != NULL) && (device_count < max_devices)) if ((devices != NULL) && (device_count < max_devices)) {
devices[device_count] = local_devices[i]; devices[device_count] = local_devices[i];
else device_count++;
} else {
drmFreeDevice(&local_devices[i]); drmFreeDevice(&local_devices[i]);
}
device_count++;
} }
closedir(sysdir); closedir(sysdir);