From d93c87f71ab07ff079ac6513a19c4fd1a1235222 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 1 Jul 2025 19:39:18 +0200 Subject: [PATCH] miext: damage: protect against NULL screen priv or funcs Protect against SEGFAULT in cases where per-screen damage private hasn't been initialized yet or already destroyed, or function pointers not implemented. Signed-off-by: Enrico Weigelt, metux IT consult --- miext/damage/damage.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/miext/damage/damage.c b/miext/damage/damage.c index 56f24d756..cfa1ae3e6 100644 --- a/miext/damage/damage.c +++ b/miext/damage/damage.c @@ -1714,7 +1714,8 @@ DamageCreate(DamageReportFunc damageReport, pDamage->damageDestroy = damageDestroy; pDamage->pScreen = pScreen; - (*pScrPriv->funcs.Create) (pDamage); + if (pScrPriv && pScrPriv->funcs.Create) + pScrPriv->funcs.Create(pDamage); return pDamage; } @@ -1755,7 +1756,8 @@ DamageRegister(DrawablePtr pDrawable, DamagePtr pDamage) pDamage->isWindow = FALSE; pDamage->pDrawable = pDrawable; damageInsertDamage(getDrawableDamageRef(pDrawable), pDamage); - (*pScrPriv->funcs.Register) (pDrawable, pDamage); + if (pScrPriv && pScrPriv->funcs.Register) + pScrPriv->funcs.Register(pDrawable, pDamage); } void @@ -1774,7 +1776,10 @@ DamageUnregister(DamagePtr pDamage) damageScrPriv(pScreen); - (*pScrPriv->funcs.Unregister) (pDrawable, pDamage); + if (pScrPriv && pScrPriv->funcs.Unregister) + pScrPriv->funcs.Unregister(pDrawable, pDamage); + else + miDamageUnregister(pDrawable, pDamage); if (pDrawable->type == DRAWABLE_WINDOW) { WindowPtr pWindow = (WindowPtr) pDrawable; @@ -1817,7 +1822,9 @@ DamageDestroy(DamagePtr pDamage) if (pDamage->damageDestroy) (*pDamage->damageDestroy) (pDamage, pDamage->closure); - (*pScrPriv->funcs.Destroy) (pDamage); + + if (pScrPriv && pScrPriv->funcs.Destroy) + pScrPriv->funcs.Destroy(pDamage); RegionUninit(&pDamage->damage); RegionUninit(&pDamage->pendingDamage); free(pDamage);