From: David Goulet Date: Tue, 3 Apr 2012 14:48:04 +0000 (-0400) Subject: Fix: check return value on getenv USER X-Git-Tag: v2.0.1~18 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=41e0febd2cd002d1e365a5996f859f50efeb86e3;p=lttng-tools.git Fix: check return value on getenv USER System with no environment variable USER, one of the easter egg caused a segfault on certain embedded linux platforms. Other getenv() of the project were audited to ensure that the return value is checked. Reported-by: Ryan Kyser Signed-off-by: David Goulet --- diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 8d6c8e621..75a467606 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -519,14 +519,17 @@ error: int main(int argc, char *argv[]) { int ret; + char *user; progname = argv[0] ? argv[0] : "lttng"; /* For Mathieu Desnoyers a.k.a. Dr. Tracing */ - if (strncmp(progname, "drtrace", 7) == 0 || - strncmp("compudj", getenv("USER"), 7) == 0) { + user = getenv("USER"); + if (user != NULL && ((strncmp(progname, "drtrace", 7) == 0 || + strncmp("compudj", user, 7) == 0))) { MSG("%c[%d;%dmWelcome back Dr Tracing!%c[%dm\n", 27,1,33,27,0); } + /* Thanks Mathieu */ ret = set_signal_handler(); if (ret < 0) {