Blame SOURCES/0001-xkb-fix-some-possible-memleaks-in-XkbGetKbdByName.patch

290b8e
From 18f91b950e22c2a342a4fbc55e9ddf7534a707d2 Mon Sep 17 00:00:00 2001
290b8e
From: Peter Hutterer <peter.hutterer@who-t.net>
290b8e
Date: Wed, 13 Jul 2022 11:23:09 +1000
290b8e
Subject: [PATCH xserver] xkb: fix some possible memleaks in XkbGetKbdByName
290b8e
290b8e
GetComponentByName returns an allocated string, so let's free that if we
290b8e
fail somewhere.
290b8e
290b8e
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
290b8e
---
290b8e
 xkb/xkb.c | 26 ++++++++++++++++++++------
290b8e
 1 file changed, 20 insertions(+), 6 deletions(-)
290b8e
290b8e
diff --git a/xkb/xkb.c b/xkb/xkb.c
290b8e
index 4692895db..b79a269e3 100644
290b8e
--- a/xkb/xkb.c
290b8e
+++ b/xkb/xkb.c
290b8e
@@ -5935,18 +5935,32 @@ ProcXkbGetKbdByName(ClientPtr client)
290b8e
     xkb = dev->key->xkbInfo->desc;
290b8e
     status = Success;
290b8e
     str = (unsigned char *) &stuff[1];
290b8e
-    if (GetComponentSpec(&str, TRUE, &status))  /* keymap, unsupported */
290b8e
-        return BadMatch;
290b8e
+    {
290b8e
+        char *keymap = GetComponentSpec(&str, TRUE, &status);  /* keymap, unsupported */
290b8e
+        if (keymap) {
290b8e
+            free(keymap);
290b8e
+            return BadMatch;
290b8e
+        }
290b8e
+    }
290b8e
     names.keycodes = GetComponentSpec(&str, TRUE, &status);
290b8e
     names.types = GetComponentSpec(&str, TRUE, &status);
290b8e
     names.compat = GetComponentSpec(&str, TRUE, &status);
290b8e
     names.symbols = GetComponentSpec(&str, TRUE, &status);
290b8e
     names.geometry = GetComponentSpec(&str, TRUE, &status);
290b8e
-    if (status != Success)
290b8e
+    if (status == Success) {
290b8e
+        len = str - ((unsigned char *) stuff);
290b8e
+        if ((XkbPaddedSize(len) / 4) != stuff->length)
290b8e
+            status = BadLength;
290b8e
+    }
290b8e
+
290b8e
+    if (status != Success) {
290b8e
+        free(names.keycodes);
290b8e
+        free(names.types);
290b8e
+        free(names.compat);
290b8e
+        free(names.symbols);
290b8e
+        free(names.geometry);
290b8e
         return status;
290b8e
-    len = str - ((unsigned char *) stuff);
290b8e
-    if ((XkbPaddedSize(len) / 4) != stuff->length)
290b8e
-        return BadLength;
290b8e
+    }
290b8e
 
290b8e
     CHK_MASK_LEGAL(0x01, stuff->want, XkbGBN_AllComponentsMask);
290b8e
     CHK_MASK_LEGAL(0x02, stuff->need, XkbGBN_AllComponentsMask);
290b8e
-- 
290b8e
2.38.1
290b8e