From 94451181c2d6f65d761cb79020a4de2909ece353 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 18 Apr 2024 18:51:36 +0200 Subject: [PATCH] xnest: fix segfault in miCreateScreenResources() With aa3f5023e3fae0df74039702b6c8218bc14dc679, pScreen->devPrivate now is initialized only once, which uncovered a silent bug in xnestOpenScreen: It's NULL'ing the pScreen->devPrivate pointer which already had been initialized by previous miScreenDevPrivateInit() call. Fixes: aa3f5023e3fae0df74039702b6c8218bc14dc679 Signed-off-by: Enrico Weigelt, metux IT consult Part-of: --- hw/xnest/Screen.c | 5 +++-- mi/mi_priv.h | 12 ++++++++++++ mi/miscrinit.c | 11 +++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 mi/mi_priv.h diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c index 14763e0e7..6eb767233 100644 --- a/hw/xnest/Screen.c +++ b/hw/xnest/Screen.c @@ -20,6 +20,8 @@ is" without express or implied warranty. #include #include +#include "mi/mi_priv.h" + #include "scrnintstr.h" #include "dix.h" #include "mi.h" @@ -257,7 +259,6 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) pScreen->blackPixel = xnestBlackPixel; /* GCperDepth */ /* defaultStipple */ - pScreen->devPrivate = NULL; /* WindowPrivateLen */ /* WindowPrivateSizes */ /* totalWindowSize */ @@ -419,7 +420,7 @@ xnestCloseScreen(ScreenPtr pScreen) free(pScreen->allowedDepths[i].vids); free(pScreen->allowedDepths); free(pScreen->visuals); - free(pScreen->devPrivate); + miScreenClose(pScreen); /* If xnestDoFullGeneration all x resources will be destroyed upon closing diff --git a/mi/mi_priv.h b/mi/mi_priv.h new file mode 100644 index 000000000..26c9d158f --- /dev/null +++ b/mi/mi_priv.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#ifndef _XSERVER_MI_PRIV_H +#define _XSERVER_MI_PRIV_H + +#include "screenint.h" + +void miScreenClose(ScreenPtr pScreen); + +#endif /* _XSERVER_MI_PRIV_H */ diff --git a/mi/miscrinit.c b/mi/miscrinit.c index 2030674a9..57571b9ab 100644 --- a/mi/miscrinit.c +++ b/mi/miscrinit.c @@ -31,6 +31,9 @@ from The Open Group. #endif #include + +#include "mi/mi_priv.h" + #include "servermd.h" #include "misc.h" #include "mi.h" @@ -309,3 +312,11 @@ miSetZeroLineBias(ScreenPtr pScreen, unsigned int bias) dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey, (unsigned long *) (unsigned long) bias); } + +void miScreenClose(ScreenPtr pScreen) +{ + if (pScreen->devPrivate) { + free(pScreen->devPrivate); + pScreen->devPrivate = NULL; + } +}