Skip to content

Commit

Permalink
Handle panic in ParseEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Mar 30, 2022
1 parent 51d7cec commit 43ab0ac
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/storage/utils/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,26 @@ type Entry struct {
// ParseEntry parses a single ACL
func ParseEntry(singleSysACL string) (*Entry, error) {
tokens := strings.Split(singleSysACL, ":")
if len(tokens) != 3 {
if len(tokens) == 2 {
// The ACL entries might be stored as type:qualifier=permissions
// Handle that case separately
parts := (strings.Split(tokens[1], "="))
tokens = []string{tokens[0], parts[0], parts[1]}
} else {
return nil, errInvalidACL
switch len(tokens) {
case 2:
// The ACL entries might be stored as type:qualifier=permissions
// Handle that case separately
parts := strings.SplitN(tokens[1], "=", 2)
if len(parts) == 2 {
return &Entry{
Type: tokens[0],
Qualifier: parts[0],
Permissions: parts[1],
}, nil
}
case 3:
return &Entry{
Type: tokens[0],
Qualifier: tokens[1],
Permissions: tokens[2],
}, nil
}

return &Entry{
Type: tokens[0],
Qualifier: tokens[1],
Permissions: tokens[2],
}, nil
return nil, errInvalidACL
}

// ParseLWEntry parses a single lightweight ACL
Expand Down

0 comments on commit 43ab0ac

Please sign in to comment.