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.6.1~105 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=5b4c34a7926b1972824c6a699937288db28cfc72;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 6d7510481..dba08bea1 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -24,6 +24,7 @@ #include #include +#include #include "../command.h" @@ -116,7 +117,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");