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

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