Skip to content

Commit

Permalink
Fix a panic (out of range on sharing credentials)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Jul 1, 2024
1 parent adcb8e9 commit 4566598
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions model/sharing/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"runtime/debug"
"time"

"github.com/cozy/cozy-stack/model/instance"
Expand Down Expand Up @@ -38,6 +39,12 @@ func (s *Sharing) SendInvitations(inst *instance.Instance, perms *permission.Per
}
state := s.Credentials[i-1].State
g.Go(func() error {
defer func() {
if r := recover(); r != nil {
inst.Logger().Errorf("[panic] %v: %s", r, debug.Stack())
}
}()

link := m.InvitationLink(inst, s, state, perms)
if m.Instance != "" && canSendShortcut {
if err := m.SendShortcut(inst, s, link); err == nil {
Expand Down
4 changes: 4 additions & 0 deletions model/sharing/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,10 @@ func (s *Sharing) FindMemberByInboundClientID(clientID string) (*Member, error)

// FindCredentials returns the credentials for the given member
func (s *Sharing) FindCredentials(m *Member) *Credentials {
if len(s.Credentials) == 0 {
return nil
}

if s.Owner {
for i, member := range s.Members {
if i > 0 && m.Same(member) {
Expand Down
6 changes: 6 additions & 0 deletions model/sharing/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/url"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -62,6 +63,11 @@ func (s *Sharing) Replicate(inst *instance.Instance, errors int) error {
}
m := &s.Members[i]
g.Go(func() error {
defer func() {
if r := recover(); r != nil {
inst.Logger().Errorf("[panic] %v: %s", r, debug.Stack())
}
}()
if m.Status == MemberStatusReady {
p, err := s.ReplicateTo(inst, m, false)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions model/sharing/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"os"
"runtime/debug"
"strings"

"github.com/cozy/cozy-stack/client/request"
Expand Down Expand Up @@ -63,6 +64,11 @@ func (s *Sharing) Upload(inst *instance.Instance, ctx context.Context, errors in
for i := range members {
m := members[i]
g.Go(func() error {
defer func() {
if r := recover(); r != nil {
inst.Logger().Errorf("[panic] %v: %s", r, debug.Stack())
}
}()
more, err := s.UploadBatchTo(inst, ctx, m, lastTry)
if err != nil {
return err
Expand Down

0 comments on commit 4566598

Please sign in to comment.