Fix: check return value on getenv USER
authorDavid Goulet <dgoulet@efficios.com>
Tue, 3 Apr 2012 14:48:04 +0000 (10:48 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 3 Apr 2012 14:54:15 +0000 (10:54 -0400)
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 <Ryan.Kyser@jci.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng/lttng.c

index 8d6c8e621e83eadd3d18a08e385ad0b474e98940..75a46760644b848d7a81fd1188b05b126a79a9e0 100644 (file)
@@ -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) {
This page took 0.025295 seconds and 4 git commands to generate.