1 | /* Test that passing a NULL value does not hang environment traversal in |
2 | tunables. |
3 | Copyright (C) 2017-2022 Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. |
5 | |
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. |
10 | |
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. |
15 | |
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/>. */ |
19 | |
20 | /* The test is useful only when the source is configured with |
21 | --enable-hardcoded-path-in-tests since otherwise the execve just picks up |
22 | the system dynamic linker. */ |
23 | |
24 | #include <stdlib.h> |
25 | #include <stdio.h> |
26 | #include <unistd.h> |
27 | #include <errno.h> |
28 | |
29 | static int |
30 | do_test (int argc, char **argv) |
31 | { |
32 | if (argc == 2) |
33 | return 0; |
34 | |
35 | char envname[] = "FOOBAR" ; |
36 | char *filename = program_invocation_name; |
37 | char *newargv[] = {filename, filename, NULL}; |
38 | char *newenviron[] = {envname, NULL}; |
39 | |
40 | /* This was reported in Fedora: |
41 | |
42 | https://bugzilla.redhat.com/show_bug.cgi?id=1414589 |
43 | |
44 | If one of the environment variables has no value, then the environment |
45 | traversal must skip and also advance to the next environment entry. The |
46 | bug in question would cause this test to hang in an infinite loop. */ |
47 | int ret = execve (path: filename, argv: newargv, envp: newenviron); |
48 | |
49 | if (ret != 0) |
50 | printf (format: "execve failed: %m" ); |
51 | |
52 | /* We will reach here only if we fail execve. */ |
53 | return 1; |
54 | } |
55 | |
56 | #define TEST_FUNCTION_ARGV do_test |
57 | #include <support/test-driver.c> |
58 | |