Skip to content

Commit ddc5437

Browse files
committed
fix: incorrect conversion between integer types
To fix the problem, we need to ensure that the value parsed by strconv.ParseUint does not exceed the maximum value that an int can hold before converting it. We can achieve this by adding a bounds check before the conversion. If the value exceeds the maximum value of an int, we should handle it appropriately, such as by setting a default value or returning an error. Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
1 parent 635ddb1 commit ddc5437

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/resources/tanzupackageinstall/spec/cluster_scope.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package spec
77

88
import (
99
"encoding/json"
10+
"math"
1011
"strconv"
1112

1213
valid "github.com/asaskevich/govalidator"
@@ -80,8 +81,12 @@ func ConstructSpecForClusterScope(d *schema.ResourceData) (spec *packageinstallm
8081
break
8182
}
8283

83-
finalIntNum := int(number) // Convert uint64 To int
84-
v1[key] = finalIntNum
84+
if number > math.MaxInt32 {
85+
v1[key] = value.(string)
86+
} else {
87+
finalIntNum := int(number) // Convert uint64 To int
88+
v1[key] = finalIntNum
89+
}
8590
case valid.IsFloat(value.(string)):
8691
floatNum, err := strconv.ParseFloat(value.(string), 64)
8792
if err != nil {

0 commit comments

Comments
 (0)