0001-xkb-fix-some-possible-memleaks-in-XkbGetKbdByName.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. CVE: CVE-2022-3551
  2. Upstream-Status: Backport
  3. Signed-off-by: Ross Burton <ross.burton@arm.com>
  4. From 18f91b950e22c2a342a4fbc55e9ddf7534a707d2 Mon Sep 17 00:00:00 2001
  5. From: Peter Hutterer <peter.hutterer@who-t.net>
  6. Date: Wed, 13 Jul 2022 11:23:09 +1000
  7. Subject: [PATCH] xkb: fix some possible memleaks in XkbGetKbdByName
  8. GetComponentByName returns an allocated string, so let's free that if we
  9. fail somewhere.
  10. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  11. ---
  12. xkb/xkb.c | 26 ++++++++++++++++++++------
  13. 1 file changed, 20 insertions(+), 6 deletions(-)
  14. diff --git a/xkb/xkb.c b/xkb/xkb.c
  15. index 4692895db..b79a269e3 100644
  16. --- a/xkb/xkb.c
  17. +++ b/xkb/xkb.c
  18. @@ -5935,18 +5935,32 @@ ProcXkbGetKbdByName(ClientPtr client)
  19. xkb = dev->key->xkbInfo->desc;
  20. status = Success;
  21. str = (unsigned char *) &stuff[1];
  22. - if (GetComponentSpec(&str, TRUE, &status)) /* keymap, unsupported */
  23. - return BadMatch;
  24. + {
  25. + char *keymap = GetComponentSpec(&str, TRUE, &status); /* keymap, unsupported */
  26. + if (keymap) {
  27. + free(keymap);
  28. + return BadMatch;
  29. + }
  30. + }
  31. names.keycodes = GetComponentSpec(&str, TRUE, &status);
  32. names.types = GetComponentSpec(&str, TRUE, &status);
  33. names.compat = GetComponentSpec(&str, TRUE, &status);
  34. names.symbols = GetComponentSpec(&str, TRUE, &status);
  35. names.geometry = GetComponentSpec(&str, TRUE, &status);
  36. - if (status != Success)
  37. + if (status == Success) {
  38. + len = str - ((unsigned char *) stuff);
  39. + if ((XkbPaddedSize(len) / 4) != stuff->length)
  40. + status = BadLength;
  41. + }
  42. +
  43. + if (status != Success) {
  44. + free(names.keycodes);
  45. + free(names.types);
  46. + free(names.compat);
  47. + free(names.symbols);
  48. + free(names.geometry);
  49. return status;
  50. - len = str - ((unsigned char *) stuff);
  51. - if ((XkbPaddedSize(len) / 4) != stuff->length)
  52. - return BadLength;
  53. + }
  54. CHK_MASK_LEGAL(0x01, stuff->want, XkbGBN_AllComponentsMask);
  55. CHK_MASK_LEGAL(0x02, stuff->need, XkbGBN_AllComponentsMask);
  56. --
  57. 2.34.1