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

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