From f0abfc19fd01adbeb942a5ba9a18ff05752ec832 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Sun, 18 Jan 2015 17:43:13 +0100 Subject: [PATCH] environ variable from C runtime is not declared on all systems --- compat.h | 4 ++++ config.h.in | 7 +++++++ configure.in | 23 +++++++++++++++++++++++ xio-openssl.c | 2 ++ 4 files changed, 36 insertions(+) diff --git a/compat.h b/compat.h index d2cc489..c8bee4d 100644 --- a/compat.h +++ b/compat.h @@ -5,6 +5,10 @@ #ifndef __compat_h_included #define __compat_h_included 1 +#if !HAVE_DECL_ENVIRON && HAVE_VAR_ENVIRON +extern char **environ; +#endif + /*****************************************************************************/ /* I dont like this system dependent part, but it would be quite a challenge for configure */ diff --git a/config.h.in b/config.h.in index b2fa202..0b30c42 100644 --- a/config.h.in +++ b/config.h.in @@ -53,6 +53,13 @@ /* Define if you have the putenv function. */ #undef HAVE_PUTENV +/* Define if your cc provides char **environ declaration. + This implies HAVE_VAR_ENVIRON */ +#undef HAVE_DECL_ENVIRON + +/* Define if you have the char **environ variable */ +#undef HAVE_VAR_ENVIRON + /* Define if you have the select function. */ #undef HAVE_SELECT diff --git a/configure.in b/configure.in index 4e0258a..c8e953f 100644 --- a/configure.in +++ b/configure.in @@ -1899,6 +1899,29 @@ if test -n "$WITH_FIPS"; then fi AC_SUBST(FIPSLD_CC) +# autoconf does not seem to provide AC_CHECK_VAR or so +# thus we have to check by foot +AC_MSG_CHECKING(for declaration of environ) +AC_CACHE_VAL(sc_cv_decl_environ, +[AC_TRY_COMPILE([#include ],[char **s = environ;], +[sc_cv_decl_environ=yes], +[sc_cv_decl_environ=no])]) +if test $sc_cv_decl_environ = yes; then + AC_DEFINE(HAVE_DECL_ENVIRON) +fi +AC_MSG_RESULT($sc_cv_decl_environ) + +# on some systems environ exists but not the declaration +AC_MSG_CHECKING(for var environ) +AC_CACHE_VAL(sc_cv_var_environ, +[AC_TRY_COMPILE([],[extern char **environ; char **s = environ;], +[sc_cv_var_environ=yes], +[sc_cv_var_environ=no])]) +if test $sc_cv_var_environ = yes; then + AC_DEFINE(HAVE_VAR_ENVIRON) +fi +AC_MSG_RESULT($sc_cv_var_environ) + # allow BUILD_DATE to be externally set for build reproducibility if test "$BUILD_DATE"; then AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"]) diff --git a/xio-openssl.c b/xio-openssl.c index fced11f..616b07c 100644 --- a/xio-openssl.c +++ b/xio-openssl.c @@ -1155,6 +1155,7 @@ static int openssl_delete_cert_info(void) { for (i = 0; i < l; ++i) envprefix[i] = toupper(envprefix[i]); strncat(envprefix+l, "_OPENSSL_", XIO_ENVNAMELEN-l-1); +#if HAVE_VAR_ENVIRON entry = (const char **)environ; while (*entry != NULL) { if (!strncmp(*entry, envprefix, strlen(envprefix))) { @@ -1166,6 +1167,7 @@ static int openssl_delete_cert_info(void) { ++entry; } } +#endif /* HAVE_VAR_ENVIRON */ return 0; }