Fix: Crash on lttng list -j/-l/-p when no events are present
[lttng-tools.git] / src / bin / lttng / commands / list.c
index a91d30757e1b9bdbd698a317aa93d286c778a038..e2cf4df5047f802925f71d043d545059fed9bea8 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <assert.h>
 
+#include <lttng/constant.h>
 #include "../command.h"
 
 static int opt_userspace;
@@ -107,7 +108,8 @@ static char *get_cmdline_by_pid(pid_t pid)
        int ret;
        FILE *fp;
        char *cmdline = NULL;
-       char path[20];  /* Can't go bigger than /proc/65535/cmdline */
+       /* Can't go bigger than /proc/LTTNG_MAX_PID/cmdline */
+       char path[sizeof("/proc//cmdline") + sizeof(LTTNG_MAX_PID_STR) - 1];
 
        snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
        fp = fopen(path, "r");
@@ -116,7 +118,7 @@ static char *get_cmdline_by_pid(pid_t pid)
        }
 
        /* Caller must free() *cmdline */
-       cmdline = malloc(PATH_MAX);
+       cmdline = zmalloc(PATH_MAX);
        if (!cmdline) {
                perror("malloc cmdline");
                goto end;
@@ -370,7 +372,7 @@ static int list_jul_events(void)
        int i, size;
        struct lttng_domain domain;
        struct lttng_handle *handle;
-       struct lttng_event *event_list;
+       struct lttng_event *event_list = NULL;
        pid_t cur_pid = 0;
        char *cmdline = NULL;
 
This page took 0.024563 seconds and 4 git commands to generate.