Skip to content

Commit

Permalink
prevent nil pointer when listing shares (#1317)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic authored Nov 12, 2020
1 parent 57eb345 commit 1c42503
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/ocs-prevent-nil-pointer.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,26 @@ 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{
Filters: filters,
}

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{
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c42503

Please sign in to comment.