a3470f
From 6869ad72b95983975675a4b920df8fea1edcfca4 Mon Sep 17 00:00:00 2001
a3470f
From: Hari Gowtham <hgowtham@redhat.com>
a3470f
Date: Thu, 12 Jul 2018 14:02:03 +0530
a3470f
Subject: [PATCH 325/325] core: dereference check on the variables in
a3470f
 glusterfs_handle_brick_status
a3470f
a3470f
	back-port of:https://review.gluster.org/#/c/20498/
a3470f
a3470f
problem: In a race condition, the active->first which is supposed to be filled
a3470f
is NULL and trying to dereference it crashs.
a3470f
a3470f
back trace:
a3470f
Core was generated by `/usr/sbin/glusterfsd -s bxts470192.eu.rabonet.com --volfile-id prod_xvavol.bxts'.
a3470f
Program terminated with signal 11, Segmentation fault.
a3470f
1029            any = active->first;
a3470f
(gdb) bt
a3470f
a3470f
>Change-Id: Ia6291865319a9456b8b01a5251be2679c4985b7c
a3470f
>fixes: bz#1600451
a3470f
>Signed-off-by: Hari Gowtham <hgowtham@redhat.com>
a3470f
a3470f
Change-Id: Ia6291865319a9456b8b01a5251be2679c4985b7c
a3470f
BUG: 1600057
a3470f
Signed-off-by: Hari Gowtham <hgowtham@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/144258
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 glusterfsd/src/glusterfsd-mgmt.c | 17 ++++++++++++++++-
a3470f
 1 file changed, 16 insertions(+), 1 deletion(-)
a3470f
a3470f
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
a3470f
index 2167241..30a717f 100644
a3470f
--- a/glusterfsd/src/glusterfsd-mgmt.c
a3470f
+++ b/glusterfsd/src/glusterfsd-mgmt.c
a3470f
@@ -1150,8 +1150,23 @@ glusterfs_handle_brick_status (rpcsvc_request_t *req)
a3470f
         }
a3470f
 
a3470f
         ctx = glusterfsd_ctx;
a3470f
-        GF_ASSERT (ctx);
a3470f
+        if (ctx == NULL) {
a3470f
+                gf_log (this->name, GF_LOG_ERROR, "ctx returned NULL");
a3470f
+                ret = -1;
a3470f
+                goto out;
a3470f
+        }
a3470f
+        if (ctx->active == NULL) {
a3470f
+                gf_log (this->name, GF_LOG_ERROR, "ctx->active returned NULL");
a3470f
+                ret = -1;
a3470f
+                goto out;
a3470f
+        }
a3470f
         active = ctx->active;
a3470f
+        if (ctx->active->first == NULL) {
a3470f
+                gf_log (this->name, GF_LOG_ERROR, "ctx->active->first "
a3470f
+                        "returned NULL");
a3470f
+                ret = -1;
a3470f
+                goto out;
a3470f
+        }
a3470f
         server_xl = active->first;
a3470f
 
a3470f
         brick_xl = get_xlator_by_name (server_xl, brickname);
a3470f
-- 
a3470f
1.8.3.1
a3470f