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

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