backend: driver: fix string out-of-bound read

libxcb doesn't null terminate strings.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-04-20 01:09:10 +01:00
parent 197e9dc866
commit b35bfd07d1
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 6 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);