Browse Source

fix: add nil/empty group validation in memory store

Guard CreateGroup and UpdateGroup against nil group or empty name
to prevent panics from nil pointer dereference on map access.
pull/8560/head
Chris Lu 1 day ago
parent
commit
0896ff6fa4
  1. 7
      weed/credential/memory/memory_group.go

7
weed/credential/memory/memory_group.go

@ -2,6 +2,7 @@ package memory
import ( import (
"context" "context"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/credential" "github.com/seaweedfs/seaweedfs/weed/credential"
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb" "github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
@ -28,6 +29,9 @@ func cloneGroup(g *iam_pb.Group) *iam_pb.Group {
} }
func (store *MemoryStore) CreateGroup(ctx context.Context, group *iam_pb.Group) error { func (store *MemoryStore) CreateGroup(ctx context.Context, group *iam_pb.Group) error {
if group == nil || group.Name == "" {
return fmt.Errorf("group name is required")
}
store.mu.Lock() store.mu.Lock()
defer store.mu.Unlock() defer store.mu.Unlock()
@ -71,6 +75,9 @@ func (store *MemoryStore) ListGroups(ctx context.Context) ([]string, error) {
} }
func (store *MemoryStore) UpdateGroup(ctx context.Context, group *iam_pb.Group) error { func (store *MemoryStore) UpdateGroup(ctx context.Context, group *iam_pb.Group) error {
if group == nil || group.Name == "" {
return fmt.Errorf("group name is required")
}
store.mu.Lock() store.mu.Lock()
defer store.mu.Unlock() defer store.mu.Unlock()

Loading…
Cancel
Save