From f1ba4547338f529aae8a269fe4c5e8075aed46a2 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 6 May 2025 14:44:13 +0200 Subject: [PATCH] dix: protect from pScreen->SetCursorPosition == NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's safer not relying on all ScreenProc's actually filled. ../dix/events.c: In function ‘CheckPhysLimits’: ../dix/events.c:780:14: warning: dereference of NULL ‘pScreen’ [CWE-476] [-Wanalyzer-null-dereference] 780 | (*pScreen->SetCursorPosition) | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Enrico Weigelt, metux IT consult --- Xi/xiwarppointer.c | 3 ++- dix/events.c | 8 +++++--- hw/xfree86/common/xf86RandR.c | 3 ++- hw/xfree86/dri/dri.c | 4 +++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Xi/xiwarppointer.c b/Xi/xiwarppointer.c index 64f1788b8..84c2db81b 100644 --- a/Xi/xiwarppointer.c +++ b/Xi/xiwarppointer.c @@ -178,7 +178,8 @@ ProcXIWarpPointer(ClientPtr client) if (pSprite->hotShape) ConfineToShape(pSprite->hotShape, &x, &y); - (*newScreen->SetCursorPosition) (pDev, newScreen, x, y, TRUE); + if (newScreen->SetCursorPosition) + newScreen->SetCursorPosition(pDev, newScreen, x, y, TRUE); } else if (!PointerConfinedToScreen(pDev)) { NewCurrentScreen(pDev, newScreen, x, y); diff --git a/dix/events.c b/dix/events.c index 8a45327ef..a257dd284 100644 --- a/dix/events.c +++ b/dix/events.c @@ -558,7 +558,9 @@ XineramaSetCursorPosition(DeviceIntPtr pDev, int x, int y, Bool generateEvent) x -= pScreen->x; y -= pScreen->y; - return (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent); + if (pScreen->SetCursorPosition) + return pScreen->SetCursorPosition(pDev, pScreen, x, y, generateEvent); + return TRUE; } static void @@ -776,8 +778,8 @@ CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor, Bool generateEvents, { if (pScreen != pSprite->hotPhys.pScreen) pSprite->hotPhys = new; - (*pScreen->SetCursorPosition) - (pDev, pScreen, new.x, new.y, generateEvents); + if (pScreen && pScreen->SetCursorPosition) + pScreen->SetCursorPosition(pDev, pScreen, new.x, new.y, generateEvents); } if (!generateEvents) SyntheticMotion(pDev, new.x, new.y); diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c index e2c498966..9f48e2c15 100644 --- a/hw/xfree86/common/xf86RandR.c +++ b/hw/xfree86/common/xf86RandR.c @@ -330,7 +330,8 @@ xf86RandRSetConfig(ScreenPtr pScreen, view_adjusted = TRUE; } - (*pScreen->SetCursorPosition) (dev, pScreen, px, py, FALSE); + if (pScreen->SetCursorPosition) + pScreen->SetCursorPosition(dev, pScreen, px, py, FALSE); } } diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c index 898e89ba2..439296f5a 100644 --- a/hw/xfree86/dri/dri.c +++ b/hw/xfree86/dri/dri.c @@ -2393,7 +2393,9 @@ DRIAdjustFrame(ScrnInfoPtr pScrn, int x, int y) py = pScrn->frameY0; if (py > pScrn->frameY1) py = pScrn->frameY1; - pScreen->SetCursorPosition(inputInfo.pointer, pScreen, px, py, TRUE); + + if (pScreen->SetCursorPosition) + pScreen->SetCursorPosition(inputInfo.pointer, pScreen, px, py, TRUE); return; }