From 730bf2af85afbd5557adac5e3283f3ad59e90194 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 10 Apr 2015 18:46:27 -0400 Subject: [PATCH] Fix: add missing getenv wrapper Required for old glibc. Signed-off-by: Mathieu Desnoyers --- liblttng-ust/Makefile.am | 3 ++- liblttng-ust/getenv.h | 44 +++++++++++++++++++++++++++++++++++++ liblttng-ust/lttng-clock.c | 3 ++- liblttng-ust/lttng-getcpu.c | 3 ++- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 liblttng-ust/getenv.h diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index bc71358f..78eac972 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -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 index 00000000..05864fb8 --- /dev/null +++ b/liblttng-ust/getenv.h @@ -0,0 +1,44 @@ +#ifndef _COMPAT_GETENV_H +#define _COMPAT_GETENV_H + +/* + * Copyright (C) 2015 - Mathieu Desnoyers + * + * 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 +#include +#include +#include + +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 */ diff --git a/liblttng-ust/lttng-clock.c b/liblttng-ust/lttng-clock.c index 557fc6b6..e8391e6d 100644 --- a/liblttng-ust/lttng-clock.c +++ b/liblttng-ust/lttng-clock.c @@ -26,6 +26,7 @@ #include #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); diff --git a/liblttng-ust/lttng-getcpu.c b/liblttng-ust/lttng-getcpu.c index 8f4c0fe7..3e675a5a 100644 --- a/liblttng-ust/lttng-getcpu.c +++ b/liblttng-ust/lttng-getcpu.c @@ -25,6 +25,7 @@ #include #include +#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); -- 2.34.1