From 972c4152fddd83a3ea58df4eff8aa5c466085075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salm=C4=81n=20Aljamm=C4=81z?= Date: Wed, 24 Dec 2014 00:08:50 +0000 Subject: [PATCH] fs: make a copy of the value buffer when setting an xattr When setting an xattr bazil.org/fuse gives us a byte slice with the attribute value to set, but it then reuses its backing array and we end up with garbage values in our xattr maps. This CL makes a copy of the slice before it stores it. Bonus edit: fix a debug message typo in muDir.Remove. Fixes #556 Change-Id: I820d8cde3065f2949ff4c506ede705194a458afb --- pkg/fs/mut.go | 2 +- pkg/fs/xattr.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/fs/mut.go b/pkg/fs/mut.go index 5d3518d33..5eafa51d3 100644 --- a/pkg/fs/mut.go +++ b/pkg/fs/mut.go @@ -432,7 +432,7 @@ func (n *mutDir) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error { claim := schema.NewDelAttributeClaim(n.permanode, "camliPath:"+req.Name, "") _, err := n.fs.client.UploadAndSignBlob(claim) if err != nil { - log.Println("mutDir.Create:", err) + log.Println("mutDir.Remove:", err) return fuse.EIO } // Remove child from map. diff --git a/pkg/fs/xattr.go b/pkg/fs/xattr.go index d2602dd75..b8c29f1a8 100644 --- a/pkg/fs/xattr.go +++ b/pkg/fs/xattr.go @@ -84,8 +84,10 @@ func (x *xattr) set(req *fuse.SetxattrRequest) fuse.Error { return fuse.EIO } + val := make([]byte, len(req.Xattr)) + copy(val, req.Xattr) x.mu.Lock() - (*x.xattrs)[req.Name] = req.Xattr + (*x.xattrs)[req.Name] = val x.mu.Unlock() return nil