Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent nil pointer when listing shares #1317

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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