Fix: add missing getenv wrapper
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 10 Apr 2015 22:46:27 +0000 (18:46 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 10 Apr 2015 22:46:27 +0000 (18:46 -0400)
Required for old glibc.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/Makefile.am
liblttng-ust/getenv.h [new file with mode: 0644]
liblttng-ust/lttng-clock.c
liblttng-ust/lttng-getcpu.c

index bc71358fe55482d4b40b474c950f190ab9f58c70..78eac9727b9710842b2cccbc79842ca8504ccc25 100644 (file)
@@ -46,7 +46,8 @@ liblttng_ust_runtime_la_SOURCES = \
        lttng-ust-uuid.h \
        error.h \
        tracef.c \
-       lttng-ust-tracef-provider.h
+       lttng-ust-tracef-provider.h \
+       getenv.h
 
 if HAVE_PERF_EVENT
 liblttng_ust_runtime_la_SOURCES += \
diff --git a/liblttng-ust/getenv.h b/liblttng-ust/getenv.h
new file mode 100644 (file)
index 0000000..05864fb
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef _COMPAT_GETENV_H
+#define _COMPAT_GETENV_H
+
+/*
+ * Copyright (C) 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <usterr-signal-safe.h>
+
+static inline
+int lttng_is_setuid_setgid(void)
+{
+       return geteuid() != getuid() || getegid() != getgid();
+}
+
+static inline
+char *lttng_secure_getenv(const char *name)
+{
+       if (lttng_is_setuid_setgid()) {
+               ERR("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.",
+                       name);
+               return NULL;
+       }
+       return getenv(name);
+}
+
+#endif /* _COMPAT_GETENV_H */
index 557fc6b6ccd7c78c612e339ceeea00d3827ba05b..e8391e6dd49f87e0efed2e99b3569c150bca8636 100644 (file)
@@ -26,6 +26,7 @@
 #include <urcu/arch.h>
 
 #include "clock.h"
+#include "getenv.h"
 
 struct lttng_trace_clock *lttng_trace_clock;
 
@@ -97,7 +98,7 @@ void lttng_ust_clock_init(void)
        void (*libinit)(void);
 
 
-       libname = secure_getenv("LTTNG_UST_CLOCK_PLUGIN");
+       libname = lttng_secure_getenv("LTTNG_UST_CLOCK_PLUGIN");
        if (!libname)
                return;
        handle = dlopen(libname, RTLD_NOW);
index 8f4c0fe7eeb6ba92c236bd2715709348c7ec45d8..3e675a5a1f422c376499065a035849084ffca4b1 100644 (file)
@@ -25,6 +25,7 @@
 #include <urcu/system.h>
 #include <urcu/arch.h>
 
+#include "getenv.h"
 #include "../libringbuffer/getcpu.h"
 
 int (*lttng_get_cpu)(void);
@@ -41,7 +42,7 @@ void lttng_ust_getcpu_init(void)
        void *handle;
        void (*libinit)(void);
 
-       libname = secure_getenv("LTTNG_UST_GETCPU_PLUGIN");
+       libname = lttng_secure_getenv("LTTNG_UST_GETCPU_PLUGIN");
        if (!libname)
                return;
        handle = dlopen(libname, RTLD_NOW);
This page took 0.026273 seconds and 4 git commands to generate.