blob: 26c5c0d2a96d8b352dd892937cf605125a2d37d3 [file] [log] [blame]
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001From dca565886b5e8bd7966e15f0ca42ee5cff686673 Mon Sep 17 00:00:00 2001
2From: DJ Delorie <dj@redhat.com>
3Date: Thu, 25 Feb 2021 16:08:21 -0500
4Subject: [PATCH] nscd: Fix double free in netgroupcache [BZ #27462]
5
6In commit 745664bd798ec8fd50438605948eea594179fba1 a use-after-free
7was fixed, but this led to an occasional double-free. This patch
8tracks the "live" allocation better.
9
10Tested manually by a third party.
11
12Related: RHBZ 1927877
13
14Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
15Reviewed-by: Carlos O'Donell <carlos@redhat.com>
16
17Upstream-Status: Backport [https://sourceware.org/git/?p=glibc.git;a=commit;h=dca565886b5e8bd7966e15f0ca42ee5cff686673]
18
19CVE: CVE-2021-27645
20
21Reviewed-by: Carlos O'Donell <carlos@redhat.com>
22Signed-off-by: Khairul Rohaizzat Jamaluddin <khairul.rohaizzat.jamaluddin@intel.com>
23---
24 nscd/netgroupcache.c | 4 ++--
25 1 file changed, 2 insertions(+), 2 deletions(-)
26
27diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
28index dba6ceec1b..ad2daddafd 100644
29--- a/nscd/netgroupcache.c
30+++ b/nscd/netgroupcache.c
31@@ -248,7 +248,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
32 : NULL);
33 ndomain = (ndomain ? newbuf + ndomaindiff
34 : NULL);
35- buffer = newbuf;
36+ *tofreep = buffer = newbuf;
37 }
38
39 nhost = memcpy (buffer + bufused,
40@@ -319,7 +319,7 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
41 else if (status == NSS_STATUS_TRYAGAIN && e == ERANGE)
42 {
43 buflen *= 2;
44- buffer = xrealloc (buffer, buflen);
45+ *tofreep = buffer = xrealloc (buffer, buflen);
46 }
47 else if (status == NSS_STATUS_RETURN
48 || status == NSS_STATUS_NOTFOUND
49--
502.27.0
51