From b35bfd07d15efa47327c74c60c8709baa7e14b6a Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 20 Apr 2019 01:09:10 +0100 Subject: [PATCH] backend: driver: fix string out-of-bound read libxcb doesn't null terminate strings. Signed-off-by: Yuxuan Shui --- src/backend/driver.c | 6 +++++- src/backend/driver.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/driver.c b/src/backend/driver.c index d4f86cf..cea58f9 100644 --- a/src/backend/driver.c +++ b/src/backend/driver.c @@ -37,7 +37,10 @@ enum driver detect_driver(xcb_connection_t *c, backend_t *backend_data, xcb_wind continue; } - auto name = xcb_randr_get_provider_info_name(r2); + auto name_len = xcb_randr_get_provider_info_name_length(r2); + assert(name_len >= 0); + auto name = + strndup(xcb_randr_get_provider_info_name(r2), (size_t)name_len); if (strcasestr(name, "modesetting") != NULL) { ret |= DRIVER_MODESETTING; } else if (strcasestr(name, "Radeon") != NULL) { @@ -50,6 +53,7 @@ enum driver detect_driver(xcb_connection_t *c, backend_t *backend_data, xcb_wind } else if (strcasestr(name, "Intel") != NULL) { ret |= DRIVER_INTEL; } + free(name); } free(r); } diff --git a/src/backend/driver.h b/src/backend/driver.h index fb10034..a575b1a 100644 --- a/src/backend/driver.h +++ b/src/backend/driver.h @@ -24,7 +24,7 @@ enum driver { DRIVER_MODESETTING = 64, }; -/// Return a list of drivers currently in use by the X server. +/// Return a list of all drivers currently in use by the X server. /// Note, this is a best-effort test, so no guarantee all drivers will be detected. enum driver detect_driver(xcb_connection_t *, struct backend_base *, xcb_window_t);