Skip to content

Commit 65a127c

Browse files
authored
Merge pull request #28 from trimble-oss/alert-autofix-271
Potential fix for code scanning alert no. 271: Incorrect conversion between integer types
2 parents fba2523 + be618c2 commit 65a127c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sql/system_settype.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,15 @@ func (t systemSetType) Convert(v interface{}) (interface{}, error) {
9191
// Float values aren't truly accepted, but the engine will give them when it should give ints.
9292
// Therefore, if the float doesn't have a fractional portion, we treat it as an int.
9393
if value >= float64(math.MinInt64) && value <= float64(math.MaxInt64) {
94-
intValue := int64(value)
95-
if float64(intValue) == value {
94+
if math.Trunc(value) == value { // Ensure no fractional part exists
95+
if value < 0 || value > math.MaxInt64 { // Additional bounds check
96+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v) // Reject out-of-range values
97+
}
98+
intValue := int64(value)
9699
return t.SetType.Convert(intValue)
97100
}
98101
}
99-
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
102+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v) // Reject out-of-range values
100103
case decimal.Decimal:
101104
f, _ := value.Float64()
102105
return t.Convert(f)

0 commit comments

Comments
 (0)