Blob Blame History Raw
From 375b3a315620ea71e44a0534f8f302deb1cce64a Mon Sep 17 00:00:00 2001
From: Kotresh HR <khiremat@redhat.com>
Date: Wed, 7 Dec 2016 07:36:19 -0500
Subject: [PATCH 233/235] glusterd/geo-rep: Fix glusterd crash

Problem:
glusterd crashes when geo-rep mountbroker setup is
created if the slave user length is more than
8 characters.

Cause:
_POSIX_LOGIN_NAME_MAX is used which is 9 including
NULL byte.

Analysis:
While the man page says it sufficient for portability, but
acutally it's not. Linux allows the creation of username
upto 32 characters by default where the max length is 256.
And NetBSD's max is 17.

Linux:
  #getconf LOGIN_NAME_MAX
   256
NetBSD:
  #getconf LOGIN_NAME_MAX
   17

Fix:
Use LOGIN_NAME_MAX instead of _POSIX_LOGIN_NAME_MAX

>Reviewed-on: http://review.gluster.org/16053
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>Reviewed-by: Aravinda VK <avishwan@redhat.com>
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>

Change-Id: I26b7230433ecbbed6e6914ed39221a478c0266a8
BUG: 1400365
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/92554
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 libglusterfs/src/compat.h                    |  4 ++++
 xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 13 +++++++++++--
 xlators/mgmt/glusterd/src/glusterd-geo-rep.h |  2 +-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index 69adfbc..ea72202 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -158,6 +158,10 @@ enum {
 #define s6_addr32 __u6_addr.__u6_addr32
 #endif
 
+#ifndef LOGIN_NAME_MAX
+#define LOGIN_NAME_MAX 256
+#endif
+
 /* Posix dictates NAME_MAX to be used */
 # ifndef NAME_MAX
 #  ifdef  MAXNAMLEN
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
index e7afb9b..a67dea1 100644
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
@@ -583,7 +583,7 @@ struct dictidxmark {
 
 struct slave_vol_config {
        char      old_slvhost[_POSIX_HOST_NAME_MAX+1];
-       char      old_slvuser[_POSIX_LOGIN_NAME_MAX];
+       char      old_slvuser[LOGIN_NAME_MAX];
        unsigned  old_slvidx;
        char      slave_voluuid[GF_UUID_BUF_SIZE];
 };
@@ -2914,6 +2914,14 @@ get_slavehost_from_voluuid (dict_t *dict, char *key, data_t *value, void *data)
                         /* To go past username in non-root geo-rep session */
                         tmp = strchr (slave_host, '@');
                         if (tmp) {
+                                if ((tmp - slave_host) >= LOGIN_NAME_MAX) {
+                                        gf_msg (this->name, GF_LOG_ERROR, 0,
+                                                GD_MSG_SLAVE_VOL_PARSE_FAIL,
+                                                "Invalid slave user length in %s",
+                                                slave_host);
+                                        ret = -2;
+                                        goto out;
+                                }
                                 strncpy (slave_vol->old_slvuser, slave_host,
                                                  (tmp - slave_host));
                                 slave_vol->old_slvuser[(tmp - slave_host) + 1]
@@ -3336,7 +3344,8 @@ glusterd_op_stage_gsync_create (dict_t *dict, char **op_errstr)
                 }
         } else if (ret == -2) {
                 snprintf (errmsg, sizeof (errmsg), "get_slavehost_from_voluuid"
-                          " failed %s %s!!", slave_host, slave_vol);
+                          " failed for %s::%s. Please check the glusterd logs.",
+                          slave_host, slave_vol);
                 gf_msg (this->name, GF_LOG_INFO, 0, GD_MSG_FORCE_CREATE_SESSION,
                         "get_slavehost_from_voluuid failed %s %s!!",
                          slave_host, slave_vol);
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.h b/xlators/mgmt/glusterd/src/glusterd-geo-rep.h
index 0524ec4..045bc2e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.h
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.h
@@ -20,7 +20,7 @@
 /* slave info format:
  * <master host uuid>:ssh://{<slave_user>@}<slave host>::<slave volume> \
  * :<slave volume uuid> */
-#define VOLINFO_SLAVE_URL_MAX (_POSIX_LOGIN_NAME_MAX + (2*GF_UUID_BUF_SIZE) \
+#define VOLINFO_SLAVE_URL_MAX (LOGIN_NAME_MAX + (2*GF_UUID_BUF_SIZE) \
                                  + SLAVE_URL_INFO_MAX + 10)
 
 typedef struct glusterd_gsync_status_temp {
-- 
2.9.3