Fix: get_cmdline_by_pid path length assumes a max pid of 65535
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 23 Jun 2015 21:27:31 +0000 (23:27 +0200)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 23 Jun 2015 21:37:24 +0000 (23:37 +0200)
PROC(5) mentions that "On 64-bit systems, pid_max can be set to any
value up to 2^22 (PID_MAX_LIMIT, approximately 4 million)."

We use 32 bits for simplicity's sake.

Reported-by: Zhenyu Ren <zhenyu.ren@aliyun.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/constant.h
src/bin/lttng/commands/list.c

index ed3ebe073b25c973495d059372a8a32e8ce091d9..10f1bf694503fc5e42d9a20632fb5c5c9c2fdce7 100644 (file)
 /*
  * Event symbol length. Copied from LTTng kernel ABI.
  */
-#define LTTNG_SYMBOL_NAME_LEN             256
+#define LTTNG_SYMBOL_NAME_LEN                  256
+
+/*
+ * PROC(5) mentions that PID_MAX_LIMIT may not exceed 2^22 on 64-bit HW.
+ * We prefer to use 32-bits for simplicity's sake.
+ */
+#define LTTNG_MAX_PID                          INT32_MAX
+#define LTTNG_MAX_PID_STR                      "2147483647"
 
 #endif /* LTTNG_CONSTANT_H */
index b436777d671b74bb2165d97eae9a5e6a1c6604e7..1eac93487a12604edb9095edb42e3ee53f08cf65 100644 (file)
@@ -25,6 +25,7 @@
 #include <assert.h>
 
 #include <common/mi-lttng.h>
+#include <lttng/constant.h>
 
 #include "../command.h"
 
@@ -106,7 +107,8 @@ static char *get_cmdline_by_pid(pid_t pid)
        int ret;
        FILE *fp = NULL;
        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");
This page took 0.025818 seconds and 4 git commands to generate.