From 4cd7fd8e6b1c3a7903107ee5eba761a0d15a4241 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 23 Jun 2015 23:27:31 +0200 Subject: [PATCH] Fix: get_cmdline_by_pid path length assumes a max pid of 65535 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- include/lttng/constant.h | 9 ++++++++- src/bin/lttng/commands/list.c | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) 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"); -- 2.39.5