Fix: segfault when print invalid command
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Jun 2013 15:19:22 +0000 (11:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Jun 2013 15:19:22 +0000 (11:19 -0400)
Fixes #556

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/helper.h
liblttng-ust/lttng-ust-comm.c

index b9448e3324febca1f1923b6ef01c53532529d36c..9d6617a8de044b2f1fa04481c9c1874cb8ffbcd2 100644 (file)
@@ -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 */
index ae2e518965e94e37a9743e7c022023eb880e206a..60beef8f43d5625fbc6554acdedf226de67b2b9c 100644 (file)
@@ -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);
 }
 
This page took 0.026258 seconds and 4 git commands to generate.