summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaushal M <kaushal@redhat.com>2018-07-10 20:56:08 +0530
committerShyamsundar Ranganathan <srangana@redhat.com>2018-07-24 10:28:55 +0000
commit9c69bdbe657d076aee71aa3d7722e7f2d61fdca2 (patch)
tree3c0ce903804d17dbb5e2df4d6bbe496bee3f284c
parent21276b31c2f6ac0978c93c0dcf8d7fe514c53b49 (diff)
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#1599785 Signed-off-by: Kaushal M <kaushal@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 42a4411d92e..ad337251b27 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1320,6 +1320,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;