From: Jérémie Galarneau Date: Tue, 23 Jun 2015 21:27:31 +0000 (+0200) Subject: Fix: get_cmdline_by_pid path length assumes a max pid of 65535 X-Git-Tag: v2.5.5~21 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4cd7fd8e6b1c3a7903107ee5eba761a0d15a4241;p=lttng-tools.git Fix: get_cmdline_by_pid path length assumes a max pid of 65535 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 Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/constant.h b/include/lttng/constant.h index ed3ebe073..10f1bf694 100644 --- a/include/lttng/constant.h +++ b/include/lttng/constant.h @@ -45,6 +45,13 @@ /* * 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 */ diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 87c99dde4..d7970a8b9 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -23,6 +23,7 @@ #include #include +#include #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");