From 4f0061d23ba96da023f9be94cf5f13c885a7b85a Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Tue, 1 Aug 2023 15:24:03 +0200 Subject: [PATCH] Fix the error handling and prevent the nil pointer error --- changelog/unreleased/fix-error-handling.md | 6 ++++++ .../ocs/handlers/apps/sharing/shares/public.go | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/fix-error-handling.md diff --git a/changelog/unreleased/fix-error-handling.md b/changelog/unreleased/fix-error-handling.md new file mode 100644 index 0000000000..8aaa039f1e --- /dev/null +++ b/changelog/unreleased/fix-error-handling.md @@ -0,0 +1,6 @@ +Bugfix: Fix the error handling + +Fix the error handling and prevent the nil pointer error + +https://github.com/cs3org/reva/pull/4093 +https://github.com/owncloud/ocis/issues/6929 diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go index 3e398ff50a..907c233ead 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go @@ -414,9 +414,17 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "missing resource information", fmt.Errorf("error getting resource information")) return } + if statRes.GetStatus().GetCode() != rpc.Code_CODE_OK { + if statRes.GetStatus().GetCode() == rpc.Code_CODE_NOT_FOUND { + response.WriteOCSError(w, r, response.MetaNotFound.StatusCode, "update public share: resource not found", err) + return + } + response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "grpc stat request failed for stat when updating a public share", err) + return + } // empty permissions mean internal link here - NOT denial. Hence we need an extra check - if !sufficientPermissions(statRes.Info.PermissionSet, newPermissions, true) { + if !sufficientPermissions(statRes.GetInfo().GetPermissionSet(), newPermissions, true) { response.WriteOCSError(w, r, http.StatusForbidden, "no share permission", nil) return }