From 016feb4b6bf4801e326e36702f66ad4f6a1c9d51 Mon Sep 17 00:00:00 2001 From: Mark Young Date: Thu, 9 Mar 2017 10:41:25 -0700 Subject: loader: Update secure_getenv check The previous check was against the compiler, not against the libc. Implement the check in CMake and generate a new header file which defines appropriate defines (loader_cmake_config.h). Change-Id: I2ae0e8d482fb4ce13089128157c11d18b0c178b9 --- loader/CMakeLists.txt | 6 ++++++ loader/loader.c | 20 ++++++++++---------- loader/loader_cmake_config.h.in | 2 ++ 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 loader/loader_cmake_config.h.in (limited to 'loader') diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt index f7f898dc..118a7c76 100644 --- a/loader/CMakeLists.txt +++ b/loader/CMakeLists.txt @@ -5,6 +5,12 @@ include_directories( ${CMAKE_BINARY_DIR} ) +# Check for the existance of the secure_getenv or __secure_getenv commands +include(CheckFunctionExists) +CHECK_FUNCTION_EXISTS(secure_getenv HAVE_SECURE_GETENV) +CHECK_FUNCTION_EXISTS(__secure_getenv HAVE___SECURE_GETENV) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/loader_cmake_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/loader_cmake_config.h) + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN) set(DisplayServer Win32) diff --git a/loader/loader.c b/loader/loader.c index 65aa9392..bf450651 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -47,6 +47,11 @@ #include "cJSON.h" #include "murmurhash.h" +// This is a CMake generated file with #defines for any functions/includes +// that it found present. This is currently necessary to properly determine +// if secure_getenv or __secure_getenv are present +#include "loader_cmake_config.h" + // Generated file containing all the extension data #include "vk_loader_extensions.c" @@ -199,20 +204,15 @@ static inline char *loader_getenv(const char *name, const struct loader_instance // the inst pointer to get rid of compiler warnings. (void)inst; -#if defined(__GNUC__) - -// Before GLIBC 2.17, the function was __secure_getenv not secure_getenv -#if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 17)) - return __secure_getenv(name); -#else +#ifdef HAVE_SECURE_GETENV return secure_getenv(name); -#endif - -// Other compilers don't support secure_getenv +#elif defined(HAVE___SECURE_GETENV) + return __secure_getenv(name); #else +#pragma message("Warning: Falling back to non-secure getenv for environmental lookups! Consider" \ + " updating to a different libc.") return getenv(name); #endif - } static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { diff --git a/loader/loader_cmake_config.h.in b/loader/loader_cmake_config.h.in new file mode 100644 index 00000000..3bbc4612 --- /dev/null +++ b/loader/loader_cmake_config.h.in @@ -0,0 +1,2 @@ +#cmakedefine HAVE_SECURE_GETENV +#cmakedefine HAVE___SECURE_GETENV -- cgit v1.2.3