1 /* Copyright (C) 2012-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 /* Verify that tunables correctly filter out unsafe environment variables like
19 MALLOC_CHECK_ and MALLOC_MMAP_THRESHOLD_ but also retain
20 MALLOC_MMAP_THRESHOLD_ in an unprivileged child. */
32 #include <support/check.h>
33 #include <support/support.h>
34 #include <support/test-driver.h>
35 #include <support/capture_subprocess.h>
37 static char SETGID_CHILD[] = "setgid-child";
43 if (getenv ("MALLOC_CHECK_") != NULL)
45 printf ("MALLOC_CHECK_ is still set\n");
49 if (getenv ("MALLOC_MMAP_THRESHOLD_") == NULL)
51 printf ("MALLOC_MMAP_THRESHOLD_ lost\n");
55 if (getenv ("LD_HWCAP_MASK") != NULL)
57 printf ("LD_HWCAP_MASK still set\n");
69 if (getenv ("MALLOC_CHECK_") == NULL)
71 printf ("MALLOC_CHECK_ lost\n");
75 if (getenv ("MALLOC_MMAP_THRESHOLD_") == NULL)
77 printf ("MALLOC_MMAP_THRESHOLD_ lost\n");
81 if (getenv ("LD_HWCAP_MASK") == NULL)
83 printf ("LD_HWCAP_MASK lost\n");
92 do_test (int argc, char **argv)
94 /* Setgid child process. */
95 if (argc == 2 && strcmp (argv[1], SETGID_CHILD) == 0)
97 if (getgid () == getegid ())
98 /* This can happen if the file system is mounted nosuid. */
99 FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n",
100 (intmax_t) getgid ());
102 int ret = test_child ();
111 if (test_parent () != 0)
114 int status = support_capture_subprogram_self_sgid (SETGID_CHILD);
116 if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
117 return EXIT_UNSUPPORTED;
119 if (!WIFEXITED (status))
120 FAIL_EXIT1 ("Unexpected exit status %d from child process\n", status);
126 #define TEST_FUNCTION_ARGV do_test
127 #include <support/test-driver.c>