From 0134ac5a3d3599cf1f3da6ff286f67d3db43adfa Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 13 Jan 2021 16:26:18 +0100 Subject: [PATCH] cairo_win32_surface_get_dc: Return NULL for error surfaces Surfaces from _cairo_surface_create_in_error() have no backend. This commit fixes a NULL pointer dereference in cairo_win32_surface_get_dc(). Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/405 Signed-off-by: Uli Schlachter --- src/win32/cairo-win32-surface.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/win32/cairo-win32-surface.c b/src/win32/cairo-win32-surface.c index f7285b92e..73078362d 100644 --- a/src/win32/cairo-win32-surface.c +++ b/src/win32/cairo-win32-surface.c @@ -155,6 +155,9 @@ _cairo_win32_surface_get_extents (void *abstract_surface, HDC cairo_win32_surface_get_dc (cairo_surface_t *surface) { + if (surface->backend == NULL) + return NULL; + if (surface->backend->type == CAIRO_SURFACE_TYPE_WIN32) return to_win32_surface(surface)->dc;