From: Mathieu Desnoyers Date: Mon, 17 Jun 2013 15:19:22 +0000 (-0400) Subject: Fix: segfault when print invalid command X-Git-Tag: v2.2.0-rc3~6 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0513bdec3c9f69aac812b77090324191957e1ef4;p=lttng-ust.git Fix: segfault when print invalid command Fixes #556 Signed-off-by: Mathieu Desnoyers --- 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); }