From ff22243955e909ae87fed280913caa569ea0c130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 3 Jul 2017 02:44:37 +0300 Subject: [PATCH] MXS-1308: Fix crash with multimaster=true The multimaster node detection uses stacks to sort the node groups. The size of this stack was always assumed to be positive but it was possible that it dropped down to -1 causing a crash when the stack was accessed with the index number. --- server/modules/monitor/mysqlmon/mysql_mon.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/modules/monitor/mysqlmon/mysql_mon.c b/server/modules/monitor/mysqlmon/mysql_mon.c index fb15f9b59..d5143faf3 100644 --- a/server/modules/monitor/mysqlmon/mysql_mon.c +++ b/server/modules/monitor/mysqlmon/mysql_mon.c @@ -845,7 +845,10 @@ static void visit_node(struct graph_node *node, struct graph_node **stack, { /** Pop invalid nodes off the stack */ node->active = false; - *stacksize -= 1; + if (*stacksize > 0) + { + *stacksize -= 1; + } } } @@ -1200,7 +1203,7 @@ monitorMain(void *arg) } - if (handle->multimaster) + if (handle->multimaster && num_servers > 0) { /** Find all the master server cycles in the cluster graph. If multiple masters are found, the servers with the read_only