Blame SOURCES/openssl-1.0.2i-secure-getenv.patch

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