1 /* Check GLIBC_TUNABLES parsing for enable_secure.
2 Copyright (C) 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 <array_length.h>
20 #include <dl-tunables.h>
25 #include <support/capture_subprocess.h>
26 #include <support/check.h>
31 #define CMDLINE_OPTIONS \
32 { "restart", no_argument, &restart, 1 },
34 static const struct test_t
37 int32_t expected_malloc_check
;
38 int32_t expected_enable_secure
;
41 /* Expected tunable format. */
42 /* Tunables should be ignored if enable_secure is set. */
44 "glibc.malloc.check=2:glibc.rtld.enable_secure=1",
48 /* Tunables should be ignored if enable_secure is set. */
50 "glibc.rtld.enable_secure=1:glibc.malloc.check=2",
54 /* Tunables should be set if enable_secure is unset. */
56 "glibc.rtld.enable_secure=0:glibc.malloc.check=2",
63 handle_restart (int i
)
65 if (tests
[i
].expected_enable_secure
== 1)
67 TEST_COMPARE (1, __libc_enable_secure
);
71 TEST_COMPARE (tests
[i
].expected_malloc_check
,
72 TUNABLE_GET_FULL (glibc
, malloc
, check
, int32_t, NULL
));
73 TEST_COMPARE (tests
[i
].expected_enable_secure
,
74 TUNABLE_GET_FULL (glibc
, rtld
, enable_secure
, int32_t,
81 do_test (int argc
, char *argv
[])
83 /* We must have either:
84 - One or four parameters left if called initially:
85 + path to ld.so optional
86 + "--library-path" optional
87 + the library path optional
88 + the application name
89 + the test to check */
91 TEST_VERIFY_EXIT (argc
== 2 || argc
== 5);
94 return handle_restart (atoi (argv
[1]));
96 char nteststr
[INT_BUFSIZE_BOUND (int)];
101 for (; i
< argc
- 1; i
++)
102 spargv
[i
] = argv
[i
+ 1];
103 spargv
[i
++] = (char *) "--direct";
104 spargv
[i
++] = (char *) "--restart";
105 spargv
[i
++] = nteststr
;
109 for (int i
= 0; i
< array_length (tests
); i
++)
111 snprintf (nteststr
, sizeof nteststr
, "%d", i
);
113 printf ("[%d] Spawned test for %s\n", i
, tests
[i
].env
);
114 setenv ("GLIBC_TUNABLES", tests
[i
].env
, 1);
115 struct support_capture_subprocess result
116 = support_capture_subprogram (spargv
[0], spargv
);
117 support_capture_subprocess_check (&result
, "tst-tunables-enable_secure",
119 support_capture_subprocess_free (&result
);
125 #define TEST_FUNCTION_ARGV do_test
126 #include <support/test-driver.c>