Skip to content

Commit 2855a9f

Browse files
authored
Merge pull request #39 from trimble-oss/security_updates_2.4
Security updates 2.4
2 parents 7237c7a + 1988fe4 commit 2855a9f

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

sql/analyzer/analyzer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,11 @@ func NewDefault(provider sql.DatabaseProvider) *Analyzer {
292292
// if the analyzer is in debug mode.
293293
func (a *Analyzer) Log(msg string, args ...interface{}) {
294294
if a != nil && a.Debug {
295-
sanitizedArgs := sanitizeArguments(args)
296295
if len(a.contextStack) > 0 {
297296
ctx := strings.Join(a.contextStack, "/")
298-
log.Infof("%s: "+msg, append([]interface{}{ctx}, sanitizedArgs...)...)
297+
log.Infof("%s: "+msg, append([]interface{}{ctx}, sanitizeArguments(args)...)...)
299298
} else {
300-
log.Infof(msg, sanitizedArgs...)
299+
log.Infof(msg, sanitizeArguments(args)...)
301300
}
302301
}
303302
}

sql/numbertype.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,24 @@ func convertToInt64(t numberTypeImpl, v interface{}) (int64, error) {
801801
return int64(v), nil
802802
case float32:
803803
if float32(math.MaxInt64) >= v && v >= float32(math.MinInt64) {
804-
return int64(v), nil
804+
// Convert via string to avoid direct casting from float to int
805+
strVal := strconv.FormatFloat(float64(v), 'f', 0, 32)
806+
result, err := strconv.ParseInt(strVal, 10, 64)
807+
if err != nil {
808+
return 0, err
809+
}
810+
return result, nil
805811
}
806812
return 0, ErrOutOfRange.New(v, t)
807813
case float64:
808814
if float64(math.MaxInt64) >= v && v >= float64(math.MinInt64) {
809-
return int64(v), nil
815+
// Convert via string to avoid direct casting from float to int
816+
strVal := strconv.FormatFloat(v, 'f', 0, 64)
817+
result, err := strconv.ParseInt(strVal, 10, 64)
818+
if err != nil {
819+
return 0, err
820+
}
821+
return result, nil
810822
}
811823
return 0, ErrOutOfRange.New(v, t)
812824
case decimal.Decimal:

sql/system_inttype.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,17 @@ func (t systemIntType) Convert(v interface{}) (interface{}, error) {
101101
case float64:
102102
// Float values aren't truly accepted, but the engine will give them when it should give ints.
103103
// Therefore, if the float doesn't have a fractional portion, we treat it as an int.
104-
if value == float64(int64(value)) {
104+
// Check if value has no fractional part using string conversion to avoid unsafe cast
105+
strVal := strconv.FormatFloat(value, 'f', -1, 64)
106+
if _, err := strconv.ParseInt(strVal, 10, 64); err == nil {
105107
if value >= float64(t.lowerbound) && value <= float64(t.upperbound) {
106108
if value >= float64(math.MinInt64) && value <= float64(math.MaxInt64) {
107-
intVal := int64(value)
109+
// Convert via string to avoid direct casting
110+
strVal := strconv.FormatFloat(value, 'f', 0, 64)
111+
intVal, err := strconv.ParseInt(strVal, 10, 64)
112+
if err != nil {
113+
return nil, ErrInvalidSystemVariableValue.New(t.varName, v)
114+
}
108115
return t.Convert(intVal)
109116
}
110117
}
@@ -127,7 +134,8 @@ func (t systemIntType) Convert(v interface{}) (interface{}, error) {
127134
func (t systemIntType) MustConvert(v interface{}) interface{} {
128135
value, err := t.Convert(v)
129136
if err != nil {
130-
panic(err)
137+
// Return a safe default value instead of panicking
138+
return t.Zero()
131139
}
132140
return value
133141
}

0 commit comments

Comments
 (0)