elf: Ignore loader debug env vars for setuid
[glibc.git] / elf / tst-audit19b.c
blobd4c9d6c3785d056b6a2605b218267366dab4bb2f
1 /* Check if DT_AUDIT a module with la_plt{enter,exit} call la_symbind
2 for lazy resolution.
3 Copyright (C) 2021-2023 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <getopt.h>
21 #include <support/capture_subprocess.h>
22 #include <support/check.h>
23 #include <support/xstdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdbool.h>
28 static int restart;
29 #define CMDLINE_OPTIONS \
30 { "restart", no_argument, &restart, 1 },
32 int tst_audit18bmod1_func (void);
34 static int
35 handle_restart (void)
37 TEST_COMPARE (tst_audit18bmod1_func (), 10);
38 return 0;
41 static inline bool
42 startswith (const char *str, const char *pre)
44 size_t lenpre = strlen (pre);
45 size_t lenstr = strlen (str);
46 return lenstr < lenpre ? false : memcmp (pre, str, lenpre) == 0;
49 static int
50 do_test (int argc, char *argv[])
52 /* We must have either:
53 - One our fource parameters left if called initially:
54 + path to ld.so optional
55 + "--library-path" optional
56 + the library path optional
57 + the application name */
59 if (restart)
60 return handle_restart ();
62 char *spargv[9];
63 int i = 0;
64 for (; i < argc - 1; i++)
65 spargv[i] = argv[i + 1];
66 spargv[i++] = (char *) "--direct";
67 spargv[i++] = (char *) "--restart";
68 spargv[i] = NULL;
70 setenv ("LD_AUDIT", "tst-auditmod18b.so", 0);
71 struct support_capture_subprocess result
72 = support_capture_subprogram (spargv[0], spargv);
73 support_capture_subprocess_check (&result, "tst-audit18b", 0, sc_allow_stderr);
75 bool find_symbind = false;
77 FILE *out = fmemopen (result.err.buffer, result.err.length, "r");
78 TEST_VERIFY (out != NULL);
79 char *buffer = NULL;
80 size_t buffer_length = 0;
81 while (xgetline (&buffer, &buffer_length, out))
82 if (startswith (buffer, "la_symbind: tst_audit18bmod1_func") == 0)
83 find_symbind = true;
85 TEST_COMPARE (find_symbind, true);
87 free (buffer);
88 xfclose (out);
90 return 0;
93 #define TEST_FUNCTION_ARGV do_test
94 #include <support/test-driver.c>