Skip to content

Commit

Permalink
session: Fix verb types
Browse files Browse the repository at this point in the history
Previously, container and object verb types were `int8` enums which is
much narrower than the protocol definition. Also, corresponding token
were converted from derived uint32 type w/o overflow check.

Now types are `int32` and any bigger value is denied.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Sep 18, 2024
1 parent 0bac9e1 commit e24d458
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions session/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package session
import (
"errors"
"fmt"
"math"

"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/session"
Expand Down Expand Up @@ -62,7 +63,11 @@ func (x *Container) readContext(c session.TokenContext, checkFieldPresence bool)
return errors.New("container conflicts with wildcard flag")
}

x.verb = ContainerVerb(cCnr.Verb())
verb := cCnr.Verb()
if verb > math.MaxInt32 {
return fmt.Errorf("verb %d overflows int32", verb)
}
x.verb = ContainerVerb(verb)

return nil
}
Expand Down Expand Up @@ -207,7 +212,7 @@ func (x Container) AppliedTo(cnr cid.ID) bool {
}

// ContainerVerb enumerates container operations.
type ContainerVerb int8
type ContainerVerb int32

const (
_ ContainerVerb = iota
Expand Down
9 changes: 7 additions & 2 deletions session/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package session
import (
"errors"
"fmt"
"math"
"slices"

"github.com/nspcc-dev/neofs-api-go/v2/refs"
Expand Down Expand Up @@ -76,7 +77,11 @@ func (x *Object) readContext(c session.TokenContext, checkFieldPresence bool) er
x.objs = nil
}

x.verb = ObjectVerb(cObj.GetVerb())
verb := cObj.GetVerb()
if verb > math.MaxInt32 {
return fmt.Errorf("verb %d overflows int32", verb)
}
x.verb = ObjectVerb(verb)

return nil
}
Expand Down Expand Up @@ -266,7 +271,7 @@ func (x Object) AssertObject(obj oid.ID) bool {
}

// ObjectVerb enumerates object operations.
type ObjectVerb int8
type ObjectVerb int32

const (
_ ObjectVerb = iota
Expand Down

0 comments on commit e24d458

Please sign in to comment.