Blob Blame History Raw
From d646605b683d18b5c368e86e7ce06da6a896d671 Mon Sep 17 00:00:00 2001
From: Atin Mukherjee <amukherj@redhat.com>
Date: Thu, 15 Jun 2017 11:31:39 +0530
Subject: [PATCH 512/525] glusterd: fix crash on statedump when no volumes are
 started

pmap object is created when glusterd allocates a port for the very first
time, however before that if someone tries to take statedump glusterd
will crash.

Solution : Add a NULL check before accessing pmap reference.

>Reviewed-on: https://review.gluster.org/17549
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Samikshan Bairagya <samikshan@gmail.com>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>

Change-Id: I206b02e07a4717e68af2c6bf05fac55119353de8
BUG: 1461649
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/109180
---
 xlators/mgmt/glusterd/src/glusterd-statedump.c | 29 +++++++++++++++-----------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-statedump.c b/xlators/mgmt/glusterd/src/glusterd-statedump.c
index 94a39be..1169c58 100644
--- a/xlators/mgmt/glusterd/src/glusterd-statedump.c
+++ b/xlators/mgmt/glusterd/src/glusterd-statedump.c
@@ -240,18 +240,23 @@ glusterd_dump_priv (xlator_t *this)
 
                 /* Dump pmap data structure from base port to last alloc */
                 pmap = priv->pmap;
-                for (port = pmap->base_port; port <= pmap->last_alloc;
-                     port++) {
-                        gf_proc_dump_build_key (key, "glusterd", "pmap_port");
-                        gf_proc_dump_write (key, "%d", port);
-                        gf_proc_dump_build_key (key, "glusterd",
-                                                "pmap[%d].type", port);
-                        gf_proc_dump_write (key, "%d", pmap->ports[port].type);
-                        gf_proc_dump_build_key (key, "glusterd",
-                                                "pmap[%d].brickname", port);
-                        gf_proc_dump_write (key, "%s",
-                                            pmap->ports[port].brickname);
-
+                if (pmap) {
+                        for (port = pmap->base_port; port <= pmap->last_alloc;
+                             port++) {
+                                gf_proc_dump_build_key (key, "glusterd",
+                                                        "pmap_port");
+                                gf_proc_dump_write (key, "%d", port);
+                                gf_proc_dump_build_key (key, "glusterd",
+                                                        "pmap[%d].type", port);
+                                gf_proc_dump_write (key, "%d",
+                                                    pmap->ports[port].type);
+                                gf_proc_dump_build_key (key, "glusterd",
+                                                        "pmap[%d].brickname",
+                                                        port);
+                                gf_proc_dump_write (key, "%s",
+                                                    pmap->ports[port].brickname);
+
+                        }
                 }
                 /* Dump client details */
                 glusterd_dump_client_details (priv);
-- 
1.8.3.1