1 From 20079c36cf7d377938ca5478447d8b9045cb7d43 Mon Sep 17 00:00:00 2001
2 From: Olivier Fourdan <ofourdan@redhat.com>
3 Date: Fri, 16 Jan 2015 08:44:45 +0100
4 Subject: [PATCH] xkb: Check strings length against request size
6 Ensure that the given strings length in an XkbSetGeometry request remain
7 within the limits of the size of the request.
9 Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
10 Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
11 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
13 Upstream-Status: backport
15 Signed-off-by: Li Zhou <li.zhou@windriver.com>
17 xkb/xkb.c | 65 +++++++++++++++++++++++++++++++++++++------------------------
18 1 file changed, 40 insertions(+), 25 deletions(-)
20 diff --git a/xkb/xkb.c b/xkb/xkb.c
21 index b9a3ac4..f3988f9 100644
24 @@ -4957,25 +4957,29 @@ ProcXkbGetGeometry(ClientPtr client)
26 /***====================================================================***/
29 -_GetCountedString(char **wire_inout, Bool swap)
31 +_GetCountedString(char **wire_inout, ClientPtr client, char **str)
38 len = *(CARD16 *) wire;
40 + if (client->swapped) {
43 - str = malloc(len + 1);
45 - memcpy(str, &wire[2], len);
48 - wire += XkbPaddedSize(len + 2);
51 + next = wire + XkbPaddedSize(len + 2);
52 + /* Check we're still within the size of the request */
53 + if (client->req_len <
54 + bytes_to_int32(next - (char *) client->requestBuffer))
56 + *str = malloc(len + 1);
59 + memcpy(*str, &wire[2], len);
60 + *(*str + len) = '\0';
66 @@ -4987,6 +4991,7 @@ _CheckSetDoodad(char **wire_inout,
67 xkbAnyDoodadWireDesc any;
68 xkbTextDoodadWireDesc text;
72 dWire = (xkbDoodadWireDesc *) (*wire_inout);
74 @@ -5036,8 +5041,14 @@ _CheckSetDoodad(char **wire_inout,
75 doodad->text.width = text.width;
76 doodad->text.height = text.height;
77 doodad->text.color_ndx = dWire->text.colorNdx;
78 - doodad->text.text = _GetCountedString(&wire, client->swapped);
79 - doodad->text.font = _GetCountedString(&wire, client->swapped);
80 + status = _GetCountedString(&wire, client, &doodad->text.text);
81 + if (status != Success)
83 + status = _GetCountedString(&wire, client, &doodad->text.font);
84 + if (status != Success) {
85 + free (doodad->text.text);
89 case XkbIndicatorDoodad:
90 if (dWire->indicator.onColorNdx >= geom->num_colors) {
91 @@ -5072,7 +5083,9 @@ _CheckSetDoodad(char **wire_inout,
93 doodad->logo.color_ndx = dWire->logo.colorNdx;
94 doodad->logo.shape_ndx = dWire->logo.shapeNdx;
95 - doodad->logo.logo_name = _GetCountedString(&wire, client->swapped);
96 + status = _GetCountedString(&wire, client, &doodad->logo.logo_name);
97 + if (status != Success)
101 client->errorValue = _XkbErrCode2(0x4F, dWire->any.type);
102 @@ -5304,18 +5317,20 @@ _CheckSetGeom(XkbGeometryPtr geom, xkbSetGeometryReq * req, ClientPtr client)
105 wire = (char *) &req[1];
106 - geom->label_font = _GetCountedString(&wire, client->swapped);
107 + status = _GetCountedString(&wire, client, &geom->label_font);
108 + if (status != Success)
111 for (i = 0; i < req->nProperties; i++) {
114 - name = _GetCountedString(&wire, client->swapped);
117 - val = _GetCountedString(&wire, client->swapped);
119 + status = _GetCountedString(&wire, client, &name);
120 + if (status != Success)
122 + status = _GetCountedString(&wire, client, &val);
123 + if (status != Success) {
128 if (XkbAddGeomProperty(geom, name, val) == NULL) {
130 @@ -5349,9 +5364,9 @@ _CheckSetGeom(XkbGeometryPtr geom, xkbSetGeometryReq * req, ClientPtr client)
131 for (i = 0; i < req->nColors; i++) {
134 - name = _GetCountedString(&wire, client->swapped);
137 + status = _GetCountedString(&wire, client, &name);
138 + if (status != Success)
140 if (!XkbAddGeomColor(geom, name, geom->num_colors)) {