Skip to content

Commit

Permalink
To fix CI warning related to conversion of integer types.
Browse files Browse the repository at this point in the history
CI unit test fix for bridgeport_test.go
  • Loading branch information
sudhar-krishnakumar committed Dec 23, 2024
1 parent a05e5fb commit 5c713f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ipu-plugin/pkg/ipuplugin/bridgeport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var _ = Describe("bridgeport", Serial, func() {
},
}
fakePortBridgeInfo := &types.BridgePortInfo{
fakePort, "fakePort1",
fakePort, 10,
}

fakeReq := &pb.CreateBridgePortRequest{BridgePort: fakePort}
Expand All @@ -131,7 +131,7 @@ var _ = Describe("bridgeport", Serial, func() {
},
}
fakePortBridgeInfo := &types.BridgePortInfo{
fakePort, "fakePort1",
fakePort, 10,
}
ipuServer.Ports["fakePort"] = fakePortBridgeInfo // fakePort already exists in internal Map

Expand Down
7 changes: 7 additions & 0 deletions ipu-plugin/pkg/ipuplugin/ipuplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ipuplugin
import (
"context"
"fmt"
"math"
"net"
"os"
"os/signal"
Expand Down Expand Up @@ -156,6 +157,12 @@ func AddAccApfsToGroupOne() error {
return fmt.Errorf("error decoding hex: %v", err)
}

// Check bounds before converting to uint
if hexVal < 0 || hexVal > math.MaxInt64 {
log.Errorf("hex value out of range: %v", hexVal)
return fmt.Errorf("hex value out of range: %v", hexVal)
}

vsiGroupInit := 0x8000050000000000 + uint(hexVal)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type uint without an upper bound check.
vsiGroupWrite := 0xA000050000000000 + uint(hexVal)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type uint without an upper bound check.

Expand Down

0 comments on commit 5c713f6

Please sign in to comment.