]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Use secure_getenv if available
authorCristian Rodríguez <crrodriguez@opensuse.org>
Mon, 11 Feb 2013 18:07:52 +0000 (15:07 -0300)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 4 Apr 2013 18:58:29 +0000 (15:58 -0300)
"The secure_getenv() function is intended for use in general-purpose
libraries to avoid vulnerabilities that could occur if set-user-ID or
set-group-ID programs accidentally trusted the environment."

configure.ac
libkmod/libkmod-private.h
libkmod/libkmod.c

index 566b317d41b2d69410678378c8d061349cdc227e..1c6c79327b7c5910d50b272849c6d3b1b941c74f 100644 (file)
@@ -39,6 +39,7 @@ PKG_PROG_PKG_CONFIG
 #####################################################################
 
 AC_CHECK_FUNCS_ONCE(__xstat)
+AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
 
 # dietlibc doesn't have st.st_mtim struct member
 AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
index 7748b143e4f4e61e68c36756092a150f9add55c8..8d8599a253a6bfa8d40cd7e0a74027c8f4c878de 100644 (file)
@@ -35,6 +35,15 @@ static _always_inline_ _printf_format_(2, 3) void
 
 #define KCMD_LINE_SIZE 4096
 
+#ifndef HAVE_SECURE_GETENV
+#  ifdef HAVE___SECURE_GETENV
+#    define secure_getenv __secure_getenv
+#  else
+#    warning neither secure_getenv nor __secure_getenv is available
+#    define secure_getenv getenv
+#  endif
+#endif
+
 void kmod_log(const struct kmod_ctx *ctx,
                int priority, const char *file, int line, const char *fn,
                const char *format, ...) __attribute__((format(printf, 6, 7))) __attribute__((nonnull(1, 3, 5)));
index b3e1d6b136c1fe54ddbd966759e5da925b1d6739..2ef19d3f6d46e4460bd77b203628d81a554f6a27 100644 (file)
@@ -254,7 +254,7 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
        ctx->dirname = get_kernel_release(dirname);
 
        /* environment overwrites config */
-       env = getenv("KMOD_LOG");
+       env = secure_getenv("KMOD_LOG");
        if (env != NULL)
                kmod_set_log_priority(ctx, log_priority(env));