From 1c425035c8a2449323a30ca79b3c103e842962f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 12 Nov 2020 14:13:16 +0100 Subject: [PATCH] prevent nil pointer when listing shares (#1317) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/ocs-prevent-nil-pointer.md | 5 +++++ .../ocs/handlers/apps/sharing/shares/public.go | 13 ++++++++----- .../ocs/handlers/apps/sharing/shares/user.go | 9 ++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 changelog/unreleased/ocs-prevent-nil-pointer.md diff --git a/changelog/unreleased/ocs-prevent-nil-pointer.md b/changelog/unreleased/ocs-prevent-nil-pointer.md new file mode 100644 index 0000000000..a6623d97bf --- /dev/null +++ b/changelog/unreleased/ocs-prevent-nil-pointer.md @@ -0,0 +1,5 @@ +Bugfix: prevent nil pointer when listing shares + +We now handle cases where the grpc connection failed correctly by no longer trying to access the response status. + +https://github.com/cs3org/reva/pull/1317 \ No newline at end of file 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 1726072709..86a5b6dd2b 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 @@ -163,11 +163,12 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh ctx := r.Context() log := appctx.GetLogger(ctx) + ocsDataPayload := make([]*conversions.ShareData, 0) // TODO(refs) why is this guard needed? Are we moving towards a gateway only for service discovery? without a gateway this is dead code. if h.gatewayAddr != "" { c, err := pool.GetGatewayServiceClient(h.gatewayAddr) if err != nil { - return nil, nil, err + return ocsDataPayload, nil, err } req := link.ListPublicSharesRequest{ @@ -175,11 +176,13 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh } res, err := c.ListPublicShares(ctx, &req) - if err != nil || res.Status.Code != rpc.Code_CODE_OK { - return nil, res.Status, err + if err != nil { + return ocsDataPayload, nil, err + } + if res.Status.Code != rpc.Code_CODE_OK { + return ocsDataPayload, res.Status, nil } - ocsDataPayload := make([]*conversions.ShareData, 0) for _, share := range res.GetShare() { statRequest := &provider.StatRequest{ @@ -215,7 +218,7 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh return ocsDataPayload, nil, nil } - return nil, nil, errors.New("bad request") + return ocsDataPayload, nil, errors.New("bad request") } func (h *Handler) isPublicShare(r *http.Request, oid string) bool { diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go index 060506b4f3..e08b57d508 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go @@ -80,13 +80,16 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.ListS // get a connection to the users share provider c, err := pool.GetGatewayServiceClient(h.gatewayAddr) if err != nil { - return nil, nil, err + return ocsDataPayload, nil, err } // do list shares request. filtered lsUserSharesResponse, err := c.ListShares(ctx, &lsUserSharesRequest) - if err != nil || lsUserSharesResponse.Status.Code != rpc.Code_CODE_OK { - return nil, lsUserSharesResponse.Status, err + if err != nil { + return ocsDataPayload, nil, err + } + if lsUserSharesResponse.Status.Code != rpc.Code_CODE_OK { + return ocsDataPayload, lsUserSharesResponse.Status, nil } // build OCS response payload