public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Fangrui Song <maskray@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/google/grte/v5-2.27/master] [BZ #22342] Fix netgroup cache keys.
Date: Sat, 28 Aug 2021 00:43:45 +0000 (GMT)	[thread overview]
Message-ID: <20210828004345.B367D385780D@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9a219419689b444a0af5d29b5917a5f239f8d6aa

commit 9a219419689b444a0af5d29b5917a5f239f8d6aa
Author: DJ Delorie <dj@redhat.com>
Date:   Thu Mar 1 23:20:45 2018 -0500

    [BZ #22342] Fix netgroup cache keys.
    
    Unlike other nscd caches, the netgroup cache contains two types of
    records - those for "iterate through a netgroup" (i.e. setnetgrent())
    and those for "is this user in this netgroup" (i.e. innetgr()),
    i.e. full and partial records.  The timeout code assumes these records
    have the same key for the group name, so that the collection of records
    that is "this netgroup" can be expired as a unit.
    
    However, the keys are not the same, as the in-netgroup key is generated
    by nscd rather than being passed to it from elsewhere, and is generated
    without the trailing NUL.  All other keys have the trailing NUL, and as
    noted in the linked BZ, debug statements confirm that two keys for the
    same netgroup are added to the cache with two different lengths.
    
    The result of this is that as records in the cache expire, the purge
    code only cleans out one of the two types of entries, resulting in
    stale, possibly incorrect, and possibly inconsistent cache data.
    
    The patch simply includes the existing NUL in the computation for the
    key length ('key' points to the char after the NUL, and 'group' to the
    first char of the group, so 'key-group' includes the first char to the
    NUL, inclusive).
    
            [BZ #22342]
            * nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
            key value.
    
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
    (cherry picked from commit 1c81d55fc4b07b51adf68558ba74ce975153e580)

Diff:
---
 ChangeLog            | 6 ++++++
 NEWS                 | 1 +
 nscd/netgroupcache.c | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index e7f672a8e2..baff9fa479 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-03-01  DJ Delorie  <dj@delorie.com>
+
+	[BZ #22342]
+	* nscd/netgroupcache.c (addinnetgrX): Include trailing NUL in
+	key value.
+
 2018-02-26  Dmitry V. Levin  <ldv@altlinux.org>
 
 	[BZ #22433]
diff --git a/NEWS b/NEWS
index d6da060f8b..ad425f2c37 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ The following bugs are resolved with this release:
 
   [6889] 'PWD' mentioned but not specified
   [16335] Feature test macro documentation incomplete and out of date
+  [22342] NSCD not properly caching netgroup
   [22638] sparc: static binaries are broken if glibc is built by gcc
     configured with --enable-default-pie
   [22735] Misleading typo in time.h source comment regarding CLOCKS_PER_SECOND
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index b832c9315f..2f187b208c 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -480,7 +480,7 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
 {
   const char *group = key;
   key = (char *) rawmemchr (key, '\0') + 1;
-  size_t group_len = key - group - 1;
+  size_t group_len = key - group;
   const char *host = *key++ ? key : NULL;
   if (host != NULL)
     key = (char *) rawmemchr (key, '\0') + 1;


                 reply	other threads:[~2021-08-28  0:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210828004345.B367D385780D@sourceware.org \
    --to=maskray@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).