a3470f
From cb681aeb67fbca52e8e0aab04a909e4bf8a62174 Mon Sep 17 00:00:00 2001
a3470f
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd@samba.org>
a3470f
Date: Mon, 9 Oct 2017 18:02:25 +0200
a3470f
Subject: [PATCH 130/139] md-cache: avoid checking the xattr value buffer with
a3470f
 string functions.
a3470f
MIME-Version: 1.0
a3470f
Content-Type: text/plain; charset=UTF-8
a3470f
Content-Transfer-Encoding: 8bit
a3470f
a3470f
xattrs may very well contain binary, non-text data with leading 0
a3470f
values. Using strcmp for checking empty values is not the appropriate
a3470f
thing to do: In the best case, it might treat a binary xattr value
a3470f
starting with 0 from being cached (and hence also from being reported
a3470f
back with xattr). In the worst case, we might read beyond the end
a3470f
of a data blob that does contain any zero byte.
a3470f
a3470f
We fix this by checking the length of the data blob and checking
a3470f
the first byte against 0 if the length is one.
a3470f
a3470f
> Signed-off-by: Guenther Deschner <gd@samba.org>
a3470f
> Pair-Programmed-With: Michael Adam <obnox@samba.org>
a3470f
> Change-Id: If723c465a630b8a37b6be58782a2724df7ac6b11
a3470f
> BUG: 1476324
a3470f
> Reviewed-on: https://review.gluster.org/17910
a3470f
> Reviewed-by: Michael Adam <obnox@samba.org>
a3470f
> Smoke: Gluster Build System <jenkins@build.gluster.org>
a3470f
> Reviewed-by: Poornima G <pgurusid@redhat.com>
a3470f
> Tested-by: Poornima G <pgurusid@redhat.com>
a3470f
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
a3470f
> (cherry picked from commit ab4ffdac9dec1867f2d9b33242179cf2b347319d)
a3470f
a3470f
Change-Id: If723c465a630b8a37b6be58782a2724df7ac6b11
a3470f
BUG: 1446125
a3470f
Signed-off-by: Günther Deschner <gd@samba.org>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/128478
a3470f
Tested-by: Poornima Gurusiddaiah <pgurusid@redhat.com>
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 tests/bugs/md-cache/bug-1476324.t           | 27 +++++++++++++++++++++++++++
a3470f
 xlators/performance/md-cache/src/md-cache.c |  2 +-
a3470f
 2 files changed, 28 insertions(+), 1 deletion(-)
a3470f
 create mode 100644 tests/bugs/md-cache/bug-1476324.t
a3470f
a3470f
diff --git a/tests/bugs/md-cache/bug-1476324.t b/tests/bugs/md-cache/bug-1476324.t
a3470f
new file mode 100644
a3470f
index 0000000..c34f412
a3470f
--- /dev/null
a3470f
+++ b/tests/bugs/md-cache/bug-1476324.t
a3470f
@@ -0,0 +1,27 @@
a3470f
+#!/bin/bash
a3470f
+
a3470f
+. $(dirname $0)/../../include.rc
a3470f
+. $(dirname $0)/../../volume.rc
a3470f
+
a3470f
+cleanup;
a3470f
+
a3470f
+TEST glusterd;
a3470f
+
a3470f
+TEST $CLI volume create $V0 $H0:$B0/${V0}{1,2,3};
a3470f
+
a3470f
+TEST $CLI volume start $V0
a3470f
+
a3470f
+TEST $CLI volume set $V0 performance.md-cache-timeout 600
a3470f
+TEST $CLI volume set $V0 performance.cache-samba-metadata on
a3470f
+
a3470f
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0
a3470f
+
a3470f
+TEST touch $M0/file1
a3470f
+
a3470f
+TEST "setfattr -n user.DOSATTRIB -v 0sAAOW $M0/file1"
a3470f
+TEST "getfattr -n user.DOSATTRIB $M0/file1 -e base64 | grep -q 0sAAOW"
a3470f
+
a3470f
+TEST "setfattr -n user.DOSATTRIB -v 0x00ff $M0/file1"
a3470f
+TEST "getfattr -n user.DOSATTRIB $M0/file1 -e hex | grep -q 0x00ff"
a3470f
+
a3470f
+cleanup;
a3470f
diff --git a/xlators/performance/md-cache/src/md-cache.c b/xlators/performance/md-cache/src/md-cache.c
a3470f
index d21a6a7..1ca7727 100644
a3470f
--- a/xlators/performance/md-cache/src/md-cache.c
a3470f
+++ b/xlators/performance/md-cache/src/md-cache.c
a3470f
@@ -633,7 +633,7 @@ updatefn(dict_t *dict, char *key, data_t *value, void *data)
a3470f
                  * not update their cache if the value of a xattr is a 0 byte
a3470f
                  * data (i.e. "").
a3470f
                  */
a3470f
-                if (!strcmp (value->data, ""))
a3470f
+                if (value->len == 1 && value->data[0] == '\0')
a3470f
                         continue;
a3470f
 
a3470f
 		if (dict_set(u->dict, key, value) < 0) {
a3470f
-- 
a3470f
1.8.3.1
a3470f