logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

shadow-4.9-gpasswd-double-free.patch (931B)


  1. https://github.com/shadow-maint/shadow/commit/117bc66c6f95fa85ca75ecfdb8fbd3615deca0b6
  2. From 117bc66c6f95fa85ca75ecfdb8fbd3615deca0b6 Mon Sep 17 00:00:00 2001
  3. From: Michael Vetter <jubalh@iodoru.org>
  4. Date: Mon, 20 Sep 2021 11:04:50 +0200
  5. Subject: [PATCH] Only free sgent if it was initialized
  6. `sgent` is only initialized in `get_group()` if `is_shadowgrp` is true.
  7. So we should also only attempt to free it if this is actually the case.
  8. Can otherwise lead to:
  9. ```
  10. free() double free detected in tcache 2 (gpasswd)
  11. ```
  12. --- a/src/gpasswd.c
  13. +++ b/src/gpasswd.c
  14. @@ -1207,11 +1207,13 @@ int main (int argc, char **argv)
  15. sssd_flush_cache (SSSD_DB_GROUP);
  16. #ifdef SHADOWGRP
  17. - if (sgent.sg_adm) {
  18. - xfree(sgent.sg_adm);
  19. - }
  20. - if (sgent.sg_mem) {
  21. - xfree(sgent.sg_mem);
  22. + if (is_shadowgrp) {
  23. + if (sgent.sg_adm) {
  24. + xfree(sgent.sg_adm);
  25. + }
  26. + if (sgent.sg_mem) {
  27. + xfree(sgent.sg_mem);
  28. + }
  29. }
  30. #endif
  31. if (grent.gr_mem) {