From eda471e6f0cbe154c47bf8a55ee66eda7354442a Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Sun, 30 Aug 2026 01:18:04 +0300 Subject: [PATCH] xnest: Check malloc return values in GCOps to avoid NULL dereferences Check malloc() return values for NULL in xnestBitBlitHelper(), xnestPolyText8(), and xnestPolyText16() to prevent potential NULL pointer dereferences --- hw/xnest/GCOps.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/xnest/GCOps.c b/hw/xnest/GCOps.c index ccc73db703..1a3c8d2631 100644 --- a/hw/xnest/GCOps.c +++ b/hw/xnest/GCOps.c @@ -189,8 +189,14 @@ xnestBitBlitHelper(GCPtr pGC) default: { struct xnest_event_queue *q = malloc(sizeof(struct xnest_event_queue)); - q->event = event; - xorg_list_add(&q->entry, &xnestUpstreamInfo.eventQueue.entry); + if (q) { + q->event = event; + xorg_list_add(&q->entry, &xnestUpstreamInfo.eventQueue.entry); + } + else { + free(event); + } + break; } } } @@ -343,6 +349,8 @@ xnestPolyText8(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count, // won't get more than 254 elements, since it's already processed by doPolyText() int const bufsize = sizeof(xTextElt) + count; uint8_t *buffer = malloc(bufsize); + if (!buffer) + return x; xTextElt *elt = (xTextElt*)buffer; elt->len = count; elt->delta = 0; @@ -369,6 +377,8 @@ xnestPolyText16(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int count, // won't get more than 254 elements, since it's already processed by doPolyText() int const bufsize = sizeof(xTextElt) + count*2; uint8_t *buffer = malloc(bufsize); + if (!buffer) + return x; xTextElt *elt = (xTextElt*)buffer; elt->len = count; elt->delta = 0;