Skip to content

Commit

Permalink
Merge pull request #2743 from lima-vm/alert-autofix-42
Browse files Browse the repository at this point in the history
Fix code scanning alert no. 42: Incorrect conversion between integer types
  • Loading branch information
AkihiroSuda authored Oct 16, 2024
2 parents 1ef9c5d + 934f5ff commit 64c3c41
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/guestagent/guestagent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (a *agent) LocalPorts(_ context.Context) ([]*api.IPPort, error) {
res = append(res,
&api.IPPort{
Ip: ipt.IP.String(),
Port: int32(ipt.Port),
Port: int32(ipt.Port), // The port value is already ensured to be within int32 bounds in iptables.go
Protocol: "tcp",
})
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/guestagent/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ func parsePortsFromRules(rules []string) ([]Entry, error) {
for _, rule := range rules {
if found := findPortRegex.FindStringSubmatch(rule); found != nil {
if len(found) == 4 {
port, err := strconv.Atoi(found[3])
port64, err := strconv.ParseInt(found[3], 10, 32)
if err != nil {
return nil, err
}
port := int(port64)

istcp := found[2] == "tcp"

Expand Down

0 comments on commit 64c3c41

Please sign in to comment.