Skip to content

Commit

Permalink
prevent nil pointer exceptions when requesting user or groups
Browse files Browse the repository at this point in the history
  • Loading branch information
rhafer committed Sep 28, 2022
1 parent b332eff commit 0f4f8e3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/users-prevent-nil-pointer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: prevent nil pointer when requesting user

We added additional nil pointer checks in the user and groups providers.

https://github.com/cs3org/reva/pull/xxxx
https://github.com/owncloud/ocis/issues/4703
18 changes: 18 additions & 0 deletions internal/grpc/services/groupprovider/groupprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func (s *service) Register(ss *grpc.Server) {
}

func (s *service) GetGroup(ctx context.Context, req *grouppb.GetGroupRequest) (*grouppb.GetGroupResponse, error) {
if req.GroupId == nil {
res := &grouppb.GetGroupResponse{
Status: status.NewInvalid(ctx, "groupid missing"),
}
return res, nil
}
group, err := s.groupmgr.GetGroup(ctx, req.GroupId, req.SkipFetchingMembers)
if err != nil {
res := &grouppb.GetGroupResponse{}
Expand Down Expand Up @@ -156,6 +162,12 @@ func (s *service) FindGroups(ctx context.Context, req *grouppb.FindGroupsRequest
}

func (s *service) GetMembers(ctx context.Context, req *grouppb.GetMembersRequest) (*grouppb.GetMembersResponse, error) {
if req.GroupId == nil {
res := &grouppb.GetMembersResponse{
Status: status.NewInvalid(ctx, "groupid missing"),
}
return res, nil
}
members, err := s.groupmgr.GetMembers(ctx, req.GroupId)
if err != nil {
return &grouppb.GetMembersResponse{
Expand All @@ -170,6 +182,12 @@ func (s *service) GetMembers(ctx context.Context, req *grouppb.GetMembersRequest
}

func (s *service) HasMember(ctx context.Context, req *grouppb.HasMemberRequest) (*grouppb.HasMemberResponse, error) {
if req.GroupId == nil || req.UserId == nil {
res := &grouppb.HasMemberResponse{
Status: status.NewInvalid(ctx, "groupid or userid missing"),
}
return res, nil
}
ok, err := s.groupmgr.HasMember(ctx, req.GroupId, req.UserId)
if err != nil {
return &grouppb.HasMemberResponse{
Expand Down
13 changes: 13 additions & 0 deletions internal/grpc/services/userprovider/userprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ func (s *service) Register(ss *grpc.Server) {
}

func (s *service) GetUser(ctx context.Context, req *userpb.GetUserRequest) (*userpb.GetUserResponse, error) {
if req.UserId == nil {
res := &userpb.GetUserResponse{
Status: status.NewInvalid(ctx, "userid missing"),
}
return res, nil
}

user, err := s.usermgr.GetUser(ctx, req.UserId, req.SkipFetchingUserGroups)
if err != nil {
res := &userpb.GetUserResponse{}
Expand Down Expand Up @@ -186,6 +193,12 @@ func (s *service) FindUsers(ctx context.Context, req *userpb.FindUsersRequest) (

func (s *service) GetUserGroups(ctx context.Context, req *userpb.GetUserGroupsRequest) (*userpb.GetUserGroupsResponse, error) {
log := appctx.GetLogger(ctx)
if req.UserId == nil {
res := &userpb.GetUserGroupsResponse{
Status: status.NewInvalid(ctx, "userid missing"),
}
return res, nil
}
groups, err := s.usermgr.GetUserGroups(ctx, req.UserId)
if err != nil {
log.Warn().Err(err).Interface("userid", req.UserId).Msg("error getting user groups")
Expand Down

0 comments on commit 0f4f8e3

Please sign in to comment.