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