From 6e8cb775df7a4b1b743fa94396b482ba10e8252f Mon Sep 17 00:00:00 2001 From: David Christofas Date: Tue, 22 Feb 2022 11:52:35 +0100 Subject: [PATCH] harden xattrs errors (#2576) * harden xattrs errors * increase lint timeout --- .drone.star | 2 +- changelog/unreleased/harden-xattrs-errors.md | 5 +++++ pkg/storage/utils/decomposedfs/xattrs/errors.go | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/harden-xattrs-errors.md diff --git a/.drone.star b/.drone.star index b192b33076..cbbe9330d3 100644 --- a/.drone.star +++ b/.drone.star @@ -29,7 +29,7 @@ def lintStep(): "name": "lint", "image": "registry.cern.ch/docker.io/golangci/golangci-lint:v1.42.1", "commands": [ - "golangci-lint run --timeout 2m0s", + "golangci-lint run --timeout 3m0s", ], } diff --git a/changelog/unreleased/harden-xattrs-errors.md b/changelog/unreleased/harden-xattrs-errors.md new file mode 100644 index 0000000000..a7d835cf8a --- /dev/null +++ b/changelog/unreleased/harden-xattrs-errors.md @@ -0,0 +1,5 @@ +Change: Harden xattrs errors + +Unwrap the error to get the root error. + +https://github.com/cs3org/reva/pull/2576 diff --git a/pkg/storage/utils/decomposedfs/xattrs/errors.go b/pkg/storage/utils/decomposedfs/xattrs/errors.go index e906376c6f..4733ce53b9 100644 --- a/pkg/storage/utils/decomposedfs/xattrs/errors.go +++ b/pkg/storage/utils/decomposedfs/xattrs/errors.go @@ -21,13 +21,14 @@ package xattrs import ( "syscall" + "github.com/pkg/errors" "github.com/pkg/xattr" ) // IsNotExist checks if there is a os not exists error buried inside the xattr error, // as we cannot just use os.IsNotExist(). func IsNotExist(err error) bool { - if xerr, ok := err.(*xattr.Error); ok { + if xerr, ok := errors.Cause(err).(*xattr.Error); ok { if serr, ok2 := xerr.Err.(syscall.Errno); ok2 { return serr == syscall.ENOENT } @@ -38,7 +39,7 @@ func IsNotExist(err error) bool { // IsAttrUnset checks the xattr.ENOATTR from the xattr package which redifines it as ENODATA on platforms that do not natively support it (eg. linux) // see https://github.com/pkg/xattr/blob/8725d4ccc0fcef59c8d9f0eaf606b3c6f962467a/xattr_linux.go#L19-L22 func IsAttrUnset(err error) bool { - if xerr, ok := err.(*xattr.Error); ok { + if xerr, ok := errors.Cause(err).(*xattr.Error); ok { if serr, ok2 := xerr.Err.(syscall.Errno); ok2 { return serr == xattr.ENOATTR }