Skip to content

Commit 64c3c41

Browse files
authored
Merge pull request #2743 from lima-vm/alert-autofix-42
Fix code scanning alert no. 42: Incorrect conversion between integer types
2 parents 1ef9c5d + 934f5ff commit 64c3c41

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

pkg/guestagent/guestagent_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (a *agent) LocalPorts(_ context.Context) ([]*api.IPPort, error) {
279279
res = append(res,
280280
&api.IPPort{
281281
Ip: ipt.IP.String(),
282-
Port: int32(ipt.Port),
282+
Port: int32(ipt.Port), // The port value is already ensured to be within int32 bounds in iptables.go
283283
Protocol: "tcp",
284284
})
285285
}

pkg/guestagent/iptables/iptables.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ func parsePortsFromRules(rules []string) ([]Entry, error) {
6767
for _, rule := range rules {
6868
if found := findPortRegex.FindStringSubmatch(rule); found != nil {
6969
if len(found) == 4 {
70-
port, err := strconv.Atoi(found[3])
70+
port64, err := strconv.ParseInt(found[3], 10, 32)
7171
if err != nil {
7272
return nil, err
7373
}
74+
port := int(port64)
7475

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

0 commit comments

Comments
 (0)