1getenv(3) Library Functions Manual getenv(3)
2
3
4
6 getenv, secure_getenv - get an environment variable
7
9 Standard C library (libc, -lc)
10
12 #include <stdlib.h>
13
14 char *getenv(const char *name);
15 char *secure_getenv(const char *name);
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 secure_getenv():
20 _GNU_SOURCE
21
23 The getenv() function searches the environment list to find the envi‐
24 ronment variable name, and returns a pointer to the corresponding value
25 string.
26
27 The GNU-specific secure_getenv() function is just like getenv() except
28 that it returns NULL in cases where "secure execution" is required.
29 Secure execution is required if one of the following conditions was
30 true when the program run by the calling process was loaded:
31
32 • the process's effective user ID did not match its real user ID or
33 the process's effective group ID did not match its real group ID
34 (typically this is the result of executing a set-user-ID or set-
35 group-ID program);
36
37 • the effective capability bit was set on the executable file; or
38
39 • the process has a nonempty permitted capability set.
40
41 Secure execution may also be required if triggered by some Linux secu‐
42 rity modules.
43
44 The secure_getenv() function is intended for use in general-purpose li‐
45 braries to avoid vulnerabilities that could occur if set-user-ID or
46 set-group-ID programs accidentally trusted the environment.
47
49 The getenv() function returns a pointer to the value in the environ‐
50 ment, or NULL if there is no match.
51
53 For an explanation of the terms used in this section, see at‐
54 tributes(7).
55
56 ┌────────────────────────────────────────┬───────────────┬─────────────┐
57 │Interface │ Attribute │ Value │
58 ├────────────────────────────────────────┼───────────────┼─────────────┤
59 │getenv(), secure_getenv() │ Thread safety │ MT-Safe env │
60 └────────────────────────────────────────┴───────────────┴─────────────┘
61
63 getenv()
64 C11, POSIX.1-2008.
65
66 secure_getenv()
67 GNU.
68
70 getenv()
71 POSIX.1-2001, C89, C99, SVr4, 4.3BSD.
72
73 secure_getenv()
74 glibc 2.17.
75
77 The strings in the environment list are of the form name=value.
78
79 As typically implemented, getenv() returns a pointer to a string within
80 the environment list. The caller must take care not to modify this
81 string, since that would change the environment of the process.
82
83 The implementation of getenv() is not required to be reentrant. The
84 string pointed to by the return value of getenv() may be statically
85 allocated, and can be modified by a subsequent call to getenv(),
86 putenv(3), setenv(3), or unsetenv(3).
87
88 The "secure execution" mode of secure_getenv() is controlled by the
89 AT_SECURE flag contained in the auxiliary vector passed from the kernel
90 to user space.
91
93 clearenv(3), getauxval(3), putenv(3), setenv(3), unsetenv(3),
94 capabilities(7), environ(7)
95
96
97
98Linux man-pages 6.05 2023-07-20 getenv(3)