From 0513bdec3c9f69aac812b77090324191957e1ef4 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 17 Jun 2013 11:19:22 -0400 Subject: [PATCH] Fix: segfault when print invalid command Fixes #556 Signed-off-by: Mathieu Desnoyers --- include/helper.h | 2 ++ liblttng-ust/lttng-ust-comm.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/helper.h b/include/helper.h index b9448e33..9d6617a8 100644 --- a/include/helper.h +++ b/include/helper.h @@ -41,4 +41,6 @@ void *zmalloc(size_t len) __min1 <= __min2 ? __min1: __min2; \ }) +#define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + #endif /* _LTTNG_UST_HELPER_H */ diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index ae2e5189..60beef8f 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -209,10 +209,12 @@ void print_cmd(int cmd, int handle) { const char *cmd_name = "Unknown"; - if (cmd_name_mapping[cmd]) { + if (cmd >= 0 && cmd < LTTNG_ARRAY_SIZE(cmd_name_mapping) + && cmd_name_mapping[cmd]) { cmd_name = cmd_name_mapping[cmd]; } - DBG("Message Received \"%s\", Handle \"%s\" (%d)", cmd_name, + DBG("Message Received \"%s\" (%d), Handle \"%s\" (%d)", + cmd_name, cmd, lttng_ust_obj_get_name(handle), handle); } -- 2.34.1