From 3aef433f970ca5595bcbabf9db841a550c677539 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 30 Apr 2024 09:57:28 +0200 Subject: [PATCH] backend/drm: handle errors when fetching DRM name/version These functions can fail if the FD is not a DRM device or on memory allocation failure, for instance. --- backend/drm/backend.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index f20050ad..5c0c77bd 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -171,7 +171,17 @@ struct wlr_backend *wlr_drm_backend_create(struct wlr_session *session, assert(!parent || wlr_backend_is_drm(parent)); char *name = drmGetDeviceNameFromFd2(dev->fd); + if (name == NULL) { + wlr_log_errno(WLR_ERROR, "drmGetDeviceNameFromFd2() failed"); + return NULL; + } + drmVersion *version = drmGetVersion(dev->fd); + if (version == NULL) { + wlr_log_errno(WLR_ERROR, "drmGetVersion() failed"); + free(name); + return NULL; + } wlr_log(WLR_INFO, "Initializing DRM backend for %s (%s)", name, version->name); drmFreeVersion(version);