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