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

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