Remove ia64-linux-gnu
[glibc.git] / nss / tst-nss-db-endpwent.c
blob6fdf6a0b4c4922c5dd2a2fb4bb1f1d2c625d09b3
1 /* Test for endpwent->getpwent crash for BZ #24695
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/types.h>
22 #include <pwd.h>
24 #include <support/support.h>
25 #include <support/check.h>
26 #include <support/xstdlib.h>
28 /* It is entirely allowed to start with a getpwent call without
29 resetting the state of the service via a call to setpwent.
30 You can also call getpwent more times than you have entries in
31 the service, and it should not fail. This test iteratates the
32 database once, gets to the end, and then attempts a second
33 iteration to look for crashes. */
35 static void
36 try_it (void)
38 struct passwd *pw;
40 /* setpwent is intentionally omitted here. The first call to
41 getpwent detects that it's first and initializes. The second
42 time try_it is called, this "first call" was not detected before
43 the fix, and getpwent would crash. */
45 while ((pw = getpwent ()) != NULL)
48 /* We only care if this segfaults or not. */
49 endpwent ();
52 static int
53 do_test (void)
55 char *cmd;
57 cmd = xasprintf ("%s/makedb -o /var/db/passwd.db /var/db/passwd.in",
58 support_bindir_prefix);
59 xsystem (cmd);
60 free (cmd);
62 try_it ();
63 try_it ();
65 return 0;
67 #include <support/test-driver.c>