From f62b21ca4a6e745f8589b257574aa2304e43871b Mon Sep 17 00:00:00 2001
From: Kaushal M <kaushal@redhat.com>
Date: Tue, 10 Jul 2018 20:56:08 +0530
Subject: [PATCH 319/325] glusterd: _is_prefix should handle 0-length paths
If one of the paths given to _is_prefix is 0-length, then it is not a
prefix of the other. Hence, _is_prefix should return false.
>Change-Id: I54aa577a64a58940ec91872d0d74dc19cff9106d
>fixes: bz#1599783
>Signed-off-by: Kaushal M <kaushal@redhat.com>
upstream patch:https://review.gluster.org/#/c/20490/
Change-Id: I54aa577a64a58940ec91872d0d74dc19cff9106d
BUG: 1599823
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/143743
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
xlators/mgmt/glusterd/src/glusterd-utils.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index f62c917..565b6c5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1318,6 +1318,15 @@ _is_prefix (char *str1, char *str2)
len1 = strlen (str1);
len2 = strlen (str2);
small_len = min (len1, len2);
+
+ /*
+ * If either one (not both) of the strings are 0-length, they are not
+ * prefixes of each other.
+ */
+ if ((small_len == 0) && (len1 != len2)) {
+ return _gf_false;
+ }
+
for (i = 0; i < small_len; i++) {
if (str1[i] != str2[i]) {
prefix = _gf_false;
--
1.8.3.1