#include <stdlib.h> char *getenv(const char *name); char *secure_getenv(const char *name);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
secure_getenv():
_GNU_SOURCE
The secure_getenv() function is just like getenv() except that it returns NULL in cases where "secure execution" is required. Secure execution is required if one of the following conditions was true when the program run by the calling process was loaded:
Linux セキュリティモジュールにより要求された場合にも "secure execution" は必要となる場合がある。
secure_getenv() 関数は、 set-user-ID プログラムや set-group-ID プログラムが実行環境を偶然信用してしまった場合に起こり得る脆弱性を、 汎用ライブラリで回避するために使うことを意図して作られた。
| インターフェース | 属性 | 値 |
| getenv(), secure_getenv() | Thread safety | MT-Safe env |
通常の実装では、 getenv() は環境リスト内の文字列へのポインターを返す。 呼び出し元はこの文字列を変更しないように注意しなければならない。 この文字列を変更すると、そのプロセスの環境を変化させることになるからである。
getenv() の実装はリエントラント (再入可能) であることを要求されていない。 getenv() の返り値により参照される文字列は静的に割り当てられてもよく、 文字列の内容は後続の getenv(), putenv(3), setenv(3), unsetenv(3) の呼び出しにより変更されることがある。
secure_getenv() の "secure execution" モードは、 カーネルからユーザー空間に渡される補助ベクトル (auxiliary vector) の AT_SECURE フラグにより制御される。