6e67274
diff -up openssl-1.0.2i/crypto/conf/conf_api.c.secure-getenv openssl-1.0.2i/crypto/conf/conf_api.c
6e67274
--- openssl-1.0.2i/crypto/conf/conf_api.c.secure-getenv	2016-09-22 12:23:06.000000000 +0200
6e67274
+++ openssl-1.0.2i/crypto/conf/conf_api.c	2016-09-22 13:51:29.847742209 +0200
a1fb602
@@ -63,6 +63,8 @@
a1fb602
 # define NDEBUG
a1fb602
 #endif
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <assert.h>
a1fb602
 #include <stdlib.h>
a1fb602
 #include <string.h>
a1fb602
@@ -141,7 +143,7 @@ char *_CONF_get_string(const CONF *conf,
a1fb602
             if (v != NULL)
a1fb602
                 return (v->value);
a1fb602
             if (strcmp(section, "ENV") == 0) {
a1fb602
-                p = getenv(name);
a1fb602
+                p = secure_getenv(name);
a1fb602
                 if (p != NULL)
a1fb602
                     return (p);
a1fb602
             }
a1fb602
@@ -154,7 +156,7 @@ char *_CONF_get_string(const CONF *conf,
a1fb602
         else
a1fb602
             return (NULL);
a1fb602
     } else
a1fb602
-        return (getenv(name));
a1fb602
+        return (secure_getenv(name));
a1fb602
 }
a1fb602
 
a1fb602
 #if 0                           /* There's no way to provide error checking
6e67274
diff -up openssl-1.0.2i/crypto/conf/conf_mod.c.secure-getenv openssl-1.0.2i/crypto/conf/conf_mod.c
6e67274
--- openssl-1.0.2i/crypto/conf/conf_mod.c.secure-getenv	2016-09-22 12:23:06.000000000 +0200
6e67274
+++ openssl-1.0.2i/crypto/conf/conf_mod.c	2016-09-22 13:51:29.847742209 +0200
a1fb602
@@ -57,6 +57,8 @@
a1fb602
  *
a1fb602
  */
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <stdio.h>
a1fb602
 #include <ctype.h>
a1fb602
 #include <openssl/crypto.h>
6e67274
@@ -530,7 +532,7 @@ char *CONF_get1_default_config_file(void
a1fb602
     char *file;
a1fb602
     int len;
a1fb602
 
a1fb602
-    file = getenv("OPENSSL_CONF");
a1fb602
+    file = secure_getenv("OPENSSL_CONF");
a1fb602
     if (file)
a1fb602
         return BUF_strdup(file);
a1fb602
 
6e67274
diff -up openssl-1.0.2i/crypto/engine/eng_list.c.secure-getenv openssl-1.0.2i/crypto/engine/eng_list.c
6e67274
--- openssl-1.0.2i/crypto/engine/eng_list.c.secure-getenv	2016-09-22 12:23:06.000000000 +0200
6e67274
+++ openssl-1.0.2i/crypto/engine/eng_list.c	2016-09-22 13:51:29.847742209 +0200
a1fb602
@@ -62,6 +62,8 @@
a1fb602
  * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
a1fb602
  */
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include "eng_int.h"
a1fb602
 
a1fb602
 /*
6e67274
@@ -369,10 +371,10 @@ ENGINE *ENGINE_by_id(const char *id)
a1fb602
      */
a1fb602
     if (strcmp(id, "dynamic")) {
a1fb602
 # ifdef OPENSSL_SYS_VMS
a1fb602
-        if ((load_dir = getenv("OPENSSL_ENGINES")) == 0)
a1fb602
+        if (OPENSSL_issetugid() || (load_dir = getenv("OPENSSL_ENGINES")) == 0)
a1fb602
             load_dir = "SSLROOT:[ENGINES]";
a1fb602
 # else
a1fb602
-        if ((load_dir = getenv("OPENSSL_ENGINES")) == 0)
a1fb602
+        if ((load_dir = secure_getenv("OPENSSL_ENGINES")) == 0)
a1fb602
             load_dir = ENGINESDIR;
a1fb602
 # endif
a1fb602
         iterator = ENGINE_by_id("dynamic");
6e67274
diff -up openssl-1.0.2i/crypto/md5/md5_dgst.c.secure-getenv openssl-1.0.2i/crypto/md5/md5_dgst.c
6e67274
--- openssl-1.0.2i/crypto/md5/md5_dgst.c.secure-getenv	2016-09-22 13:51:29.840742047 +0200
6e67274
+++ openssl-1.0.2i/crypto/md5/md5_dgst.c	2016-09-22 13:51:29.847742209 +0200
a1fb602
@@ -56,6 +56,8 @@
a1fb602
  * [including the GNU Public Licence.]
a1fb602
  */
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <stdio.h>
a1fb602
 #include "md5_locl.h"
a1fb602
 #include <openssl/opensslv.h>
a1fb602
@@ -75,7 +77,8 @@ const char MD5_version[] = "MD5" OPENSSL
a1fb602
 int MD5_Init(MD5_CTX *c)
a1fb602
 #ifdef OPENSSL_FIPS
a1fb602
 {
a1fb602
-    if (FIPS_mode() && getenv("OPENSSL_FIPS_NON_APPROVED_MD5_ALLOW") == NULL)
a1fb602
+    if (FIPS_mode()
a1fb602
+        && secure_getenv("OPENSSL_FIPS_NON_APPROVED_MD5_ALLOW") == NULL)
a1fb602
         OpenSSLDie(__FILE__, __LINE__, "Digest MD5 forbidden in FIPS mode!");
a1fb602
     return private_MD5_Init(c);
a1fb602
 }
6e67274
diff -up openssl-1.0.2i/crypto/o_init.c.secure-getenv openssl-1.0.2i/crypto/o_init.c
6e67274
--- openssl-1.0.2i/crypto/o_init.c.secure-getenv	2016-09-22 13:51:29.830741814 +0200
6e67274
+++ openssl-1.0.2i/crypto/o_init.c	2016-09-22 13:51:30.046746834 +0200
a1fb602
@@ -53,6 +53,8 @@
a1fb602
  *
a1fb602
  */
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <e_os.h>
a1fb602
 #include <openssl/err.h>
a1fb602
 #ifdef OPENSSL_FIPS
a1fb602
@@ -72,7 +74,7 @@ static void init_fips_mode(void)
a1fb602
     char buf[2] = "0";
a1fb602
     int fd;
a1fb602
 
a1fb602
-    if (getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
a1fb602
+    if (secure_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
a1fb602
         buf[0] = '1';
a1fb602
     } else if ((fd = open(FIPS_MODE_SWITCH_FILE, O_RDONLY)) >= 0) {
a1fb602
         while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR) ;
6e67274
diff -up openssl-1.0.2i/crypto/rand/randfile.c.secure-getenv openssl-1.0.2i/crypto/rand/randfile.c
6e67274
--- openssl-1.0.2i/crypto/rand/randfile.c.secure-getenv	2016-09-22 12:23:06.000000000 +0200
6e67274
+++ openssl-1.0.2i/crypto/rand/randfile.c	2016-09-22 13:53:17.222237626 +0200
6e67274
@@ -55,6 +55,8 @@
6e67274
  * copied and put under another distribution licence
6e67274
  * [including the GNU Public Licence.]
6e67274
  */
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 
a1fb602
 #include <errno.h>
a1fb602
 #include <stdio.h>
6e67274
@@ -327,14 +329,12 @@ const char *RAND_file_name(char *buf, si
a1fb602
     struct stat sb;
a1fb602
 #endif
a1fb602
 
a1fb602
-    if (OPENSSL_issetugid() == 0)
a1fb602
-        s = getenv("RANDFILE");
a1fb602
+    s = secure_getenv("RANDFILE");
a1fb602
     if (s != NULL && *s && strlen(s) + 1 < size) {
a1fb602
         if (BUF_strlcpy(buf, s, size) >= size)
a1fb602
             return NULL;
a1fb602
     } else {
a1fb602
-        if (OPENSSL_issetugid() == 0)
a1fb602
-            s = getenv("HOME");
a1fb602
+        s = secure_getenv("HOME");
a1fb602
 #ifdef DEFAULT_HOME
a1fb602
         if (s == NULL) {
a1fb602
             s = DEFAULT_HOME;
6e67274
diff -up openssl-1.0.2i/crypto/x509/by_dir.c.secure-getenv openssl-1.0.2i/crypto/x509/by_dir.c
6e67274
--- openssl-1.0.2i/crypto/x509/by_dir.c.secure-getenv	2016-09-22 12:23:06.000000000 +0200
6e67274
+++ openssl-1.0.2i/crypto/x509/by_dir.c	2016-09-22 13:51:30.047746858 +0200
a1fb602
@@ -56,6 +56,8 @@
a1fb602
  * [including the GNU Public Licence.]
a1fb602
  */
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <stdio.h>
a1fb602
 #include <time.h>
a1fb602
 #include <errno.h>
a1fb602
@@ -128,7 +130,7 @@ static int dir_ctrl(X509_LOOKUP *ctx, in
a1fb602
     switch (cmd) {
a1fb602
     case X509_L_ADD_DIR:
a1fb602
         if (argl == X509_FILETYPE_DEFAULT) {
a1fb602
-            dir = (char *)getenv(X509_get_default_cert_dir_env());
a1fb602
+            dir = (char *)secure_getenv(X509_get_default_cert_dir_env());
a1fb602
             if (dir)
a1fb602
                 ret = add_cert_dir(ld, dir, X509_FILETYPE_PEM);
a1fb602
             else
6e67274
diff -up openssl-1.0.2i/crypto/x509/by_file.c.secure-getenv openssl-1.0.2i/crypto/x509/by_file.c
6e67274
--- openssl-1.0.2i/crypto/x509/by_file.c.secure-getenv	2016-09-22 13:51:29.812741396 +0200
6e67274
+++ openssl-1.0.2i/crypto/x509/by_file.c	2016-09-22 13:51:30.047746858 +0200
a1fb602
@@ -56,6 +56,8 @@
a1fb602
  * [including the GNU Public Licence.]
a1fb602
  */
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <stdio.h>
a1fb602
 #include <time.h>
a1fb602
 #include <errno.h>
a1fb602
@@ -97,7 +99,7 @@ static int by_file_ctrl(X509_LOOKUP *ctx
a1fb602
     switch (cmd) {
a1fb602
     case X509_L_FILE_LOAD:
a1fb602
         if (argl == X509_FILETYPE_DEFAULT) {
a1fb602
-            file = (char *)getenv(X509_get_default_cert_file_env());
a1fb602
+            file = (char *)secure_getenv(X509_get_default_cert_file_env());
a1fb602
             if (file)
a1fb602
                 ok = (X509_load_cert_crl_file(ctx, file,
a1fb602
                                               X509_FILETYPE_PEM) != 0);
6e67274
diff -up openssl-1.0.2i/crypto/x509/x509_vfy.c.secure-getenv openssl-1.0.2i/crypto/x509/x509_vfy.c
6e67274
--- openssl-1.0.2i/crypto/x509/x509_vfy.c.secure-getenv	2016-09-22 12:23:06.000000000 +0200
6e67274
+++ openssl-1.0.2i/crypto/x509/x509_vfy.c	2016-09-22 13:51:30.048746881 +0200
a1fb602
@@ -56,6 +56,8 @@
a1fb602
  * [including the GNU Public Licence.]
a1fb602
  */
a1fb602
 
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <stdio.h>
a1fb602
 #include <time.h>
a1fb602
 #include <errno.h>
6e67274
@@ -620,7 +622,7 @@ static int check_chain_extensions(X509_S
a1fb602
          * A hack to keep people who don't want to modify their software
a1fb602
          * happy
a1fb602
          */
a1fb602
-        if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
a1fb602
+        if (secure_getenv("OPENSSL_ALLOW_PROXY_CERTS"))
a1fb602
             allow_proxy_certs = 1;
a1fb602
         purpose = ctx->param->purpose;
a1fb602
     }
6e67274
diff -up openssl-1.0.2i/engines/ccgost/gost_ctl.c.secure-getenv openssl-1.0.2i/engines/ccgost/gost_ctl.c
6e67274
--- openssl-1.0.2i/engines/ccgost/gost_ctl.c.secure-getenv	2016-09-22 12:23:06.000000000 +0200
6e67274
+++ openssl-1.0.2i/engines/ccgost/gost_ctl.c	2016-09-22 13:51:30.048746881 +0200
a1fb602
@@ -6,6 +6,8 @@
a1fb602
  *        Implementation of control commands for GOST engine          *
a1fb602
  *            OpenSSL 0.9.9 libraries required                        *
a1fb602
  **********************************************************************/
a1fb602
+/* for secure_getenv */
a1fb602
+#define _GNU_SOURCE
a1fb602
 #include <stdlib.h>
a1fb602
 #include <string.h>
a1fb602
 #include <openssl/crypto.h>
a1fb602
@@ -64,7 +66,7 @@ const char *get_gost_engine_param(int pa
a1fb602
     if (gost_params[param] != NULL) {
a1fb602
         return gost_params[param];
a1fb602
     }
a1fb602
-    tmp = getenv(gost_envnames[param]);
a1fb602
+    tmp = secure_getenv(gost_envnames[param]);
a1fb602
     if (tmp) {
a1fb602
         if (gost_params[param])
a1fb602
             OPENSSL_free(gost_params[param]);
a1fb602
@@ -79,7 +81,7 @@ int gost_set_default_param(int param, co
a1fb602
     const char *tmp;
a1fb602
     if (param < 0 || param > GOST_PARAM_MAX)
a1fb602
         return 0;
a1fb602
-    tmp = getenv(gost_envnames[param]);
a1fb602
+    tmp = secure_getenv(gost_envnames[param]);
a1fb602
     /*
a1fb602
      * if there is value in the environment, use it, else -passed string *
a1fb602
      */