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.7.0-rc1~27 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fae9a062a468c47fc71ef7aa96374bf9d87d137e;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 b436777d6..1eac93487 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -25,6 +25,7 @@ #include #include +#include #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");