]> git.ipfire.org Git - thirdparty/glibc.git/blob - nss/tst-nss-files-alias-truncated.c
nss_files: Fix /etc/aliases null pointer dereference [BZ #24059]
[thirdparty/glibc.git] / nss / tst-nss-files-alias-truncated.c
1 /* Check handling of missing end-of-line at end of /etc/aliases (bug 24059).
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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 <http://www.gnu.org/licenses/>. */
18
19 #include <aliases.h>
20 #include <nss.h>
21 #include <stddef.h>
22 #include <support/check.h>
23 #include <support/namespace.h>
24 #include <support/test-driver.h>
25 #include <support/xunistd.h>
26
27 static void
28 in_chroot (void *closure)
29 {
30 struct support_chroot *chroot_env = closure;
31 xchroot (chroot_env->path_chroot);
32
33 struct aliasent *e = getaliasbyname ("user1");
34 TEST_VERIFY_EXIT (e != NULL);
35 TEST_COMPARE_STRING (e->alias_name, "user1");
36 TEST_COMPARE (e->alias_members_len, 1);
37 TEST_VERIFY_EXIT (e->alias_members != NULL);
38 TEST_COMPARE_STRING (e->alias_members[0], "alias1");
39 TEST_VERIFY (e->alias_local);
40 }
41
42 static int
43 do_test (void)
44 {
45 /* nss_files has already been loaded via DT_NEEDED, outside the
46 chroot. */
47 __nss_configure_lookup ("aliases", "files");
48
49 support_become_root ();
50 if (!support_can_chroot ())
51 return EXIT_UNSUPPORTED;
52
53 struct support_chroot *chroot_env = support_chroot_create
54 ((struct support_chroot_configuration)
55 {
56 .aliases = "user1: alias1,\n"
57 " " /* Continuation line, but no \n. */
58 });
59
60 support_isolate_in_subprocess (in_chroot, chroot_env);
61
62 support_chroot_free (chroot_env);
63 return 0;
64 }
65
66 #include <support/test-driver.c>