Blame nss/tst-nss-db-endgrent.c

Packit Service 0b5c9d
/* Test for endgrent changing errno for BZ #24696
Packit Service 0b5c9d
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit Service 0b5c9d
   This file is part of the GNU C Library.
Packit Service 0b5c9d
Packit Service 0b5c9d
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 0b5c9d
   modify it under the terms of the GNU Lesser General Public
Packit Service 0b5c9d
   License as published by the Free Software Foundation; either
Packit Service 0b5c9d
   version 2.1 of the License, or (at your option) any later version.
Packit Service 0b5c9d
Packit Service 0b5c9d
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 0b5c9d
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 0b5c9d
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 0b5c9d
   Lesser General Public License for more details.
Packit Service 0b5c9d
Packit Service 0b5c9d
   You should have received a copy of the GNU Lesser General Public
Packit Service 0b5c9d
   License along with the GNU C Library; if not, see
Packit Service 0b5c9d
   <http://www.gnu.org/licenses/>.  */
Packit Service 0b5c9d
Packit Service 0b5c9d
#include <stdlib.h>
Packit Service 0b5c9d
#include <sys/types.h>
Packit Service 0b5c9d
#include <grp.h>
Packit Service 0b5c9d
#include <unistd.h>
Packit Service 0b5c9d
#include <errno.h>
Packit Service 0b5c9d
Packit Service 0b5c9d
#include <support/check.h>
Packit Service 0b5c9d
#include <support/support.h>
Packit Service 0b5c9d
Packit Service 0b5c9d
/* The following test verifies that if the db NSS Service is initialized
Packit Service 0b5c9d
   with no database (getgrent), that a subsequent closure (endgrent) does
Packit Service 0b5c9d
   not set errno. In the case of the db service it is not an error to close
Packit Service 0b5c9d
   the service and so it should not set errno.  */
Packit Service 0b5c9d
Packit Service 0b5c9d
static int
Packit Service 0b5c9d
do_test (void)
Packit Service 0b5c9d
{
Packit Service 0b5c9d
  /* Just make sure it's not there, although usually it won't be.  */
Packit Service 0b5c9d
  unlink ("/var/db/group.db");
Packit Service 0b5c9d
Packit Service 0b5c9d
  /* This, in conjunction with the testroot's nsswitch.conf, causes
Packit Service 0b5c9d
     the nss_db module to be "connected" and initialized - but the
Packit Service 0b5c9d
     testroot has no group.db, so no mapping will be created.  */
Packit Service 0b5c9d
  getgrent ();
Packit Service 0b5c9d
Packit Service 0b5c9d
  errno = 0;
Packit Service 0b5c9d
Packit Service 0b5c9d
  /* Before the fix, this would call munmap (NULL) and set errno.  */
Packit Service 0b5c9d
  endgrent ();
Packit Service 0b5c9d
Packit Service 0b5c9d
  if (errno != 0)
Packit Service 0b5c9d
    FAIL_EXIT1 ("endgrent set errno to %d\n", errno);
Packit Service 0b5c9d
Packit Service 0b5c9d
  return 0;
Packit Service 0b5c9d
}
Packit Service 0b5c9d
#include <support/test-driver.c>