Skip to content

Commit

Permalink
Fix conversion (#5993)
Browse files Browse the repository at this point in the history
* fix the string to int conversion

* fix the string to int conversion

* fix the string to int conversion

* fix formating
  • Loading branch information
Behnam-Shobiri authored May 10, 2022
1 parent 1ab9c49 commit 650b470
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions felix/fv/pktgen/pktgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"math"
"net"
"strconv"

Expand Down Expand Up @@ -60,6 +61,9 @@ func main() {
if err != nil {
log.WithError(err).Fatal("IP id not a number")
}
if id > math.MaxUint16 || id < 0 {
log.Fatal("IP id should be between 0 and 65535")
}
ipID = uint16(id)
}

Expand All @@ -69,6 +73,9 @@ func main() {
if err != nil {
log.WithError(err).Fatal("source port not a number")
}
if p > math.MaxUint16 || p < 0 {
log.Fatal("source port should be between 0 and 65535")
}
sport = uint16(p)
}

Expand All @@ -78,6 +85,9 @@ func main() {
if err != nil {
log.WithError(err).Fatal("destination port not a number")
}
if p > math.MaxUint16 || p < 0 {
log.Fatal("destination port should be between 0 and 65535")
}
dport = uint16(p)
}

Expand Down
4 changes: 4 additions & 0 deletions felix/ipsets/ipset_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"fmt"
"math"
"strconv"

cprometheus "github.com/projectcalico/calico/libcalico-go/lib/prometheus"
Expand Down Expand Up @@ -153,6 +154,9 @@ func (t IPSetType) CanonicaliseMember(member string) ipSetMember {
if err != nil {
log.WithField("member", member).WithError(err).Panic("Bad port")
}
if port > math.MaxUint16 || port < 0 {
log.WithField("member", member).Panic("Bad port range (should be between 0 and 65535)")
}
// Return a dedicated struct for V4 or V6. This slightly reduces occupancy over storing
// the address as an interface by storing one fewer interface headers. That is worthwhile
// because we store many IP set members.
Expand Down
4 changes: 4 additions & 0 deletions libcalico-go/lib/testutils/createRule.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package testutils

import (
"log"
"math"
"net"
"strconv"

Expand All @@ -34,6 +35,9 @@ func CreateRule(ipv, icmpType, icmpCode int, proto, cidrStr, tag, selector, inAc
if err != nil {
protocol = numorstring.ProtocolFromString(proto)
} else {
if i > math.MaxUint8 || i < 0 {
log.Printf("i = %v should be between 0 and 255 \n", i)
}
protocol = numorstring.ProtocolFromInt(uint8(i))
}

Expand Down

0 comments on commit 650b470

Please sign in to comment.