unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* nss_db: protect against empty mappings
@ 2019-06-18  0:28 DJ Delorie
  2019-06-18  2:35 ` Carlos O'Donell
  0 siblings, 1 reply; 44+ messages in thread
From: DJ Delorie @ 2019-06-18  0:28 UTC (permalink / raw)
  To: libc-alpha


Resolves: #24696

(note to reviewers: Sergi contributed the one-line fix, I did the
rest, for the purposes of copyright-line-counts)

2019-06-17  DJ Delorie  <dj@redhat.com>
	    Sergei Trofimovich <slyfox@inbox.ru>

	* nss/nss_db/db-open.c (internal_endent): Protect against NULL
	mappings.
	* nss/tst-nss-db-endgrent.c: New.
	* nss/tst-nss-db-endgrent.root: New.
	* nss/Makefile: Add new test.

diff --git a/nss/Makefile b/nss/Makefile
index 15fc410cf1..a15c3b7d90 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -62,7 +62,8 @@ xtests			= bug-erange
 tests-container = \
 			  tst-nss-test3 \
 			  tst-nss-files-hosts-long \
-			  tst-nss-db-endpwent
+			  tst-nss-db-endpwent \
+			  tst-nss-db-endgrent
 
 # Tests which need libdl
 ifeq (yes,$(build-shared))
diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c
index f7c53b4486..3fa11e9ab0 100644
--- a/nss/nss_db/db-open.c
+++ b/nss/nss_db/db-open.c
@@ -63,6 +63,9 @@ internal_setent (const char *file, struct nss_db_map *mapping)
 void
 internal_endent (struct nss_db_map *mapping)
 {
-  munmap (mapping->header, mapping->len);
-  mapping->header = NULL;
+  if (mapping->header != NULL)
+    {
+      munmap (mapping->header, mapping->len);
+      mapping->header = NULL;
+    }
 }
diff --git a/nss/tst-nss-db-endgrent.c b/nss/tst-nss-db-endgrent.c
new file mode 100644
index 0000000000..f4c1e14d60
--- /dev/null
+++ b/nss/tst-nss-db-endgrent.c
@@ -0,0 +1,46 @@
+/* Test for endgrent changing errno.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <grp.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <support/check.h>
+#include <support/support.h>
+
+
+static int
+do_test (void)
+{
+  /* Just make sure it's not there, although usually it won't be.  */
+  unlink ("/var/db/group.db");
+
+  getgrent ();
+
+  int saved_errno = errno;
+
+  endgrent ();
+
+  if (errno != saved_errno)
+    FAIL_EXIT1 ("endgrent changed errno from %d o %d\n", saved_errno, errno);
+
+  return 0;
+}
+#include <support/test-driver.c>
diff --git a/nss/tst-nss-db-endgrent.root/etc/nsswitch.conf b/nss/tst-nss-db-endgrent.root/etc/nsswitch.conf
new file mode 100644
index 0000000000..21471df94f
--- /dev/null
+++ b/nss/tst-nss-db-endgrent.root/etc/nsswitch.conf
@@ -0,0 +1 @@
+group : db files

^ permalink raw reply related	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2019-07-18 18:44 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18  0:28 nss_db: protect against empty mappings DJ Delorie
2019-06-18  2:35 ` Carlos O'Donell
2019-06-18  3:15   ` DJ Delorie
2019-06-18  3:33     ` Carlos O'Donell
2019-06-18  4:12       ` DJ Delorie
2019-06-18  6:12         ` Florian Weimer
2019-06-18 13:18           ` Carlos O'Donell
2019-06-18 17:47           ` DJ Delorie
2019-06-18 18:15             ` Carlos O'Donell
2019-06-18 18:28               ` [PATCH v4] " DJ Delorie
2019-06-18 18:58               ` [PATCH v5] " DJ Delorie
2019-06-19  7:45             ` Andreas Schwab
2019-06-19 16:31               ` DJ Delorie
2019-06-19 16:33                 ` Florian Weimer
2019-06-19 16:56                   ` [PATCH V6] " DJ Delorie
2019-06-20  1:02                     ` Carlos O'Donell
2019-06-24  8:19                 ` Andreas Schwab
2019-06-24 23:51                   ` DJ Delorie
2019-06-25  7:56                     ` Andreas Schwab
2019-06-25 21:29                       ` [PATCHv7] " DJ Delorie
2019-06-25 21:36                         ` Florian Weimer
2019-06-28 13:38                           ` Florian Weimer
2019-06-28 19:20                             ` DJ Delorie
2019-06-28 19:23                               ` Florian Weimer
2019-06-28 19:29                                 ` DJ Delorie
2019-06-28 22:32                             ` [PATCHv8] " DJ Delorie
2019-07-08 23:22                               ` DJ Delorie
2019-07-10  9:51                               ` Florian Weimer
2019-07-10 18:52                                 ` DJ Delorie
2019-07-12  0:12                                   ` Rafal Luzynski
2019-07-12  4:21                                     ` DJ Delorie
2019-07-12 10:24                                       ` Rafal Luzynski
2019-07-12 11:36                                         ` Carlos O'Donell
2019-07-12 20:19                                           ` DJ Delorie
2019-07-13  2:09                                             ` Carlos O'Donell
2019-07-13  3:13                                               ` DJ Delorie
2019-07-18 18:20                                                 ` Carlos O'Donell
2019-07-18 18:44                                                   ` DJ Delorie
2019-07-16  9:54                                           ` CI/CD in glibc (was: nss_db: protect against empty mappings) Rafal Luzynski
2019-07-16 12:00                                             ` CI/CD in glibc Florian Weimer
2019-07-16 20:14                                               ` Carlos O'Donell
2019-07-17 17:58                                               ` Zack Weinberg
2019-07-17 19:05                                                 ` Florian Weimer
2019-07-12 19:58                                         ` [PATCHv8] nss_db: protect against empty mappings DJ Delorie

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).