]> 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)
committerDJ Delorie <dj@redhat.com>
Tue, 2 Mar 2021 17:32:18 +0000 (12:32 -0500)
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>
nscd/netgroupcache.c

index dba6ceec1be490bfae78ff4573a9aed5189e05f1..ad2daddafdc9d80cf81178415f22e3649ee64f52 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