Fix: get_cmdline_by_pid path length assumes a max pid of 65535
[lttng-tools.git] / src / bin / lttng / commands / list.c
index f56adf4821db71ca4d8d4f77bc7adabd36444302..d7970a8b9ab2e0a2553ef5475d66fbc3ebd7d460 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;
@@ -720,7 +722,7 @@ static int list_channels(const char *channel_name)
                goto error_channels;
        }
 
-       if (channel_name == NULL) {
+       if (count) {
                MSG("Channels:\n-------------");
        }
 
This page took 0.025133 seconds and 4 git commands to generate.