Commit 1abdf082 authored by Pauli's avatar Pauli
Browse files

Use secure_getenv(3) when available.



Change all calls to getenv() inside libcrypto to use a new wrapper function
that use secure_getenv() if available and an issetugid then getenv if not.

CPU processor override flags are unchanged.

Extra checks for OPENSSL_issetugid() have been removed in favour of the
safe getenv.

Reviewed-by: default avatarBernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/7047)

(cherry picked from commit 5c39a55d)
parent 4aa1739c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ LIBS=../libcrypto
SOURCE[../libcrypto]=\
        cryptlib.c mem.c mem_dbg.c cversion.c ex_data.c cpt_err.c \
        ebcdic.c uid.c o_time.c o_str.c o_dir.c o_fopen.c \
        threads_pthread.c threads_win.c threads_none.c \
        threads_pthread.c threads_win.c threads_none.c getenv.c \
        o_init.c o_fips.c mem_sec.c init.c {- $target{cpuid_asm_src} -} \
        {- $target{uplink_aux_src} -}
EXTRA=  ../ms/uplink-x86.pl ../ms/uplink.c ../ms/applink.c \
+4 −3
Original line number Diff line number Diff line
@@ -9,11 +9,12 @@

/* Part of the code in here was originally in conf.c, which is now removed */

#include "e_os.h"
#include "internal/cryptlib.h"
#include <stdlib.h>
#include <string.h>
#include <openssl/conf.h>
#include <openssl/conf_api.h>
#include "e_os.h"

static void value_free_hash(const CONF_VALUE *a, LHASH_OF(CONF_VALUE) *conf);
static void value_free_stack_doall(CONF_VALUE *a);
@@ -82,7 +83,7 @@ char *_CONF_get_string(const CONF *conf, const char *section,
            if (v != NULL)
                return (v->value);
            if (strcmp(section, "ENV") == 0) {
                p = getenv(name);
                p = ossl_safe_getenv(name);
                if (p != NULL)
                    return (p);
            }
@@ -95,7 +96,7 @@ char *_CONF_get_string(const CONF *conf, const char *section,
        else
            return (NULL);
    } else
        return (getenv(name));
        return ossl_safe_getenv(name);
}

static unsigned long conf_value_hash(const CONF_VALUE *v)
+1 −2
Original line number Diff line number Diff line
@@ -478,8 +478,7 @@ char *CONF_get1_default_config_file(void)
    char *file;
    int len;

    file = getenv("OPENSSL_CONF");
    if (file)
    if ((file = ossl_safe_getenv("OPENSSL_CONF")) != NULL)
        return OPENSSL_strdup(file);

    len = strlen(X509_get_default_cert_area());
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ static int ctlog_new_from_conf(CTLOG **ct_log, const CONF *conf, const char *sec

int CTLOG_STORE_load_default_file(CTLOG_STORE *store)
{
    const char *fpath = getenv(CTLOG_FILE_EVP);
    const char *fpath = ossl_safe_getenv(CTLOG_FILE_EVP);

    if (fpath == NULL)
      fpath = CTLOG_FILE;
+1 −1
Original line number Diff line number Diff line
@@ -322,7 +322,7 @@ ENGINE *ENGINE_by_id(const char *id)
     * Prevent infinite recursion if we're looking for the dynamic engine.
     */
    if (strcmp(id, "dynamic")) {
        if ((load_dir = getenv("OPENSSL_ENGINES")) == 0)
        if ((load_dir = ossl_safe_getenv("OPENSSL_ENGINES")) == NULL)
            load_dir = ENGINESDIR;
        iterator = ENGINE_by_id("dynamic");
        if (!iterator || !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) ||
Loading