hardening: Use __secure_getenv if available
authorColin Walters <walters@verbum.org>
Fri, 28 Sep 2012 01:29:29 +0000 (21:29 -0400)
committerColin Walters <walters@verbum.org>
Fri, 28 Sep 2012 16:55:38 +0000 (12:55 -0400)
This helps us in the case where we were executed via filesystem
capabilities or a SELinux domain transition, not necessarily a plain
old setuid binary.

https://bugs.freedesktop.org/show_bug.cgi?id=52202

configure.ac
dbus/dbus-sysdeps.c

index df90985..4eb530a 100644 (file)
@@ -596,7 +596,7 @@ AC_DEFINE_UNQUOTED([DBUS_USE_SYNC], [$have_sync], [Use the gcc __sync extension]
 AC_SEARCH_LIBS(socket,[socket network])
 AC_CHECK_FUNC(gethostbyname,,[AC_CHECK_LIB(nsl,gethostbyname)])
 
-AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll setlocale localeconv strtoll strtoull issetugid getresuid)
+AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll setlocale localeconv strtoll strtoull issetugid getresuid secure_getenv __secure_getenv )
 
 AC_CHECK_HEADERS([syslog.h])
 if test "x$ac_cv_header_syslog_h" = "xyes"; then
index 04fb8d7..976c7e4 100644 (file)
@@ -182,12 +182,18 @@ _dbus_setenv (const char *varname,
 const char*
 _dbus_getenv (const char *varname)
 {  
+#if defined(HAVE_SECURE_GETENV)
+  return secure_getenv (varname);
+#elif defined(HAVE___SECURE_GETENV)
+  return __secure_getenv (varname);
+#else
   /* Don't respect any environment variables if the current process is
    * setuid.  This is the equivalent of glibc's __secure_getenv().
    */
   if (_dbus_check_setuid ())
     return NULL;
   return getenv (varname);
+#endif
 }
 
 /**