xkb: Fix out-of-bounds array access in xkmread.c ReadXkmGeometry

The primary_ndx and approx_ndx fields from the XKM shape wire
description are used as indices into the shape->outlines[] array without
bounds checking against num_outlines.

Exploiting this (if it can be exploited) requires a malicious xkbcomp -
the path of which is built-in at compile time. There are lower-hanging
targets than trying to exploit through an XKM file.

Assisted-by: Claude:claude-claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2207>
This commit is contained in:
Peter Hutterer 2026-04-18 09:23:52 +10:00 committed by Marge Bot
parent a439a7340a
commit 04386fb205

View file

@ -1132,9 +1132,11 @@ ReadXkmGeometry(FILE * file, XkbDescPtr xkb)
shape->bounds.y2 = ptWire.y;
}
}
if (shapeWire.primary_ndx != XkbNoShape)
if (shapeWire.primary_ndx != XkbNoShape &&
shapeWire.primary_ndx < shapeWire.num_outlines)
shape->primary = &shape->outlines[shapeWire.primary_ndx];
if (shapeWire.approx_ndx != XkbNoShape)
if (shapeWire.approx_ndx != XkbNoShape &&
shapeWire.approx_ndx < shapeWire.num_outlines)
shape->approx = &shape->outlines[shapeWire.approx_ndx];
}
}