Skip to content

Commit

Permalink
Check the number of digits at the casting
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Jun 12, 2024
1 parent e3c3416 commit 82b257d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/pkg/table/sr_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func (p *SRPolicy) Update(df PolicyDiff) {
}
}

const SRV6_SID_BIT_LENGTH = 128

type Segment interface {
SidString() string
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ func (s *APIServer) createSRPolicy(_ context.Context, input *pb.CreateSRPolicyIn
if err != nil {
return &pb.RequestStatus{IsSuccess: false}, errors.New("invalid SidStructure information")
}
segSRv6.Structure = append(segSRv6.Structure, uint8(elem))
if elem <= table.SRV6_SID_BIT_LENGTH {
segSRv6.Structure = append(segSRv6.Structure, uint8(elem))
} else {
return &pb.RequestStatus{IsSuccess: false}, errors.New("element of each Sid Structure less than bit length of SRv6 SID")
}
}

}
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package server

import (
"errors"
"math"
"net"
"net/netip"
"strconv"
Expand Down Expand Up @@ -88,6 +90,9 @@ func (s *Server) Serve(address string, port string, usidMode bool) error {
if err != nil {
return err
}
if p > math.MaxUint16 {
return errors.New("invalid PCEP listen port")
}
localAddr := netip.AddrPortFrom(a, uint16(p))

s.logger.Info("Start listening on PCEP port", zap.String("address", localAddr.String()))
Expand Down

0 comments on commit 82b257d

Please sign in to comment.