]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nscd: Fix double free in netgroupcache [BZ #27462]
authorDJ Delorie <dj@redhat.com>
Thu, 25 Feb 2021 21:08:21 +0000 (16:08 -0500)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Mon, 8 Mar 2021 10:12:15 +0000 (15:42 +0530)
In commit 745664bd798ec8fd50438605948eea594179fba1 a use-after-free
was fixed, but this led to an occasional double-free.  This patch
tracks the "live" allocation better.

Tested manually by a third party.

Related: RHBZ 1927877

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit dca565886b5e8bd7966e15f0ca42ee5cff686673)

nscd/netgroupcache.c

index 9a9783318b852703e98ecd510bfc8190627595e9..703c77ef3336b110992651f6c89587291e75064a 100644 (file)
@@ -248,7 +248,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
                                             : NULL);
                                    ndomain = (ndomain ? newbuf + ndomaindiff
                                               : NULL);
-                                   buffer = newbuf;
+                                   *tofreep = buffer = newbuf;
                                  }
 
                                nhost = memcpy (buffer + bufused,
@@ -319,7 +319,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
                    else if (status == NSS_STATUS_TRYAGAIN && e == ERANGE)
                      {
                        buflen *= 2;
-                       buffer = xrealloc (buffer, buflen);
+                       *tofreep = buffer = xrealloc (buffer, buflen);
                      }
                    else if (status == NSS_STATUS_RETURN
                             || status == NSS_STATUS_NOTFOUND