diff --git a/pkg/ffapi/handler.go b/pkg/ffapi/handler.go index 504ce8a..717bf54 100644 --- a/pkg/ffapi/handler.go +++ b/pkg/ffapi/handler.go @@ -278,7 +278,7 @@ func (hs *HandlerFactory) handleOutput(ctx context.Context, res http.ResponseWri } if marshalErr != nil { err := i18n.WrapError(ctx, marshalErr, i18n.MsgResponseMarshalError) - log.L(ctx).Errorf(err.Error()) + log.L(ctx).Error(err.Error()) return 500, err } return status, nil diff --git a/pkg/ffapi/openapi3.go b/pkg/ffapi/openapi3.go index 262d179..77911a1 100644 --- a/pkg/ffapi/openapi3.go +++ b/pkg/ffapi/openapi3.go @@ -394,7 +394,7 @@ func (sg *SwaggerGen) addRoute(ctx context.Context, doc *openapi3.T, route *Rout } else { routeDescription = i18n.Expand(ctx, route.Description) if routeDescription == "" && sg.options.PanicOnMissingDescription { - log.Panicf(i18n.NewError(ctx, i18n.MsgRouteDescriptionMissing, route.Name).Error()) + log.Panic(i18n.NewError(ctx, i18n.MsgRouteDescriptionMissing, route.Name).Error()) } } op := &openapi3.Operation{ diff --git a/pkg/ffapi/query_fields.go b/pkg/ffapi/query_fields.go index b379bb4..7f14a05 100644 --- a/pkg/ffapi/query_fields.go +++ b/pkg/ffapi/query_fields.go @@ -22,6 +22,7 @@ import ( "database/sql/driver" "encoding/json" "fmt" + "math" "math/big" "reflect" "strconv" @@ -110,11 +111,11 @@ func (f *stringField) Scan(src interface{}) error { case int64: f.s = strconv.FormatInt(tv, 10) case uint: - f.s = strconv.FormatInt(int64(tv), 10) + f.s = strconv.FormatUint(uint64(tv), 10) case uint32: - f.s = strconv.FormatInt(int64(tv), 10) + f.s = strconv.FormatUint(uint64(tv), 10) case uint64: - f.s = strconv.FormatInt(int64(tv), 10) + f.s = strconv.FormatUint(tv, 10) case *fftypes.UUID: if tv != nil { f.s = tv.String() @@ -242,10 +243,16 @@ func (f *int64Field) Scan(src interface{}) (err error) { case int64: f.i = tv case uint: + if tv > math.MaxInt64 { + return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i) + } f.i = int64(tv) case uint32: f.i = int64(tv) case uint64: + if tv > math.MaxInt64 { + return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i) + } f.i = int64(tv) case string: f.i, err = strconv.ParseInt(src.(string), 10, 64) @@ -277,10 +284,16 @@ func (f *bigIntField) Scan(src interface{}) (err error) { case int64: f.i = fftypes.NewFFBigInt(tv) case uint: + if tv > math.MaxInt64 { + return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i) + } f.i = fftypes.NewFFBigInt(int64(tv)) case uint32: f.i = fftypes.NewFFBigInt(int64(tv)) case uint64: + if tv > math.MaxInt64 { + return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i) + } f.i = fftypes.NewFFBigInt(int64(tv)) case fftypes.FFBigInt: i := tv diff --git a/pkg/fftypes/int.go b/pkg/fftypes/int.go index 628ac89..0771b71 100644 --- a/pkg/fftypes/int.go +++ b/pkg/fftypes/int.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -45,7 +45,7 @@ func (i *FFuint64) UnmarshalJSON(b []byte) error { if !ok { return i18n.NewError(context.Background(), i18n.MsgBigIntParseFailed, b) } - *i = FFuint64(bi.Int64()) + *i = FFuint64(bi.Uint64()) return nil case float64: *i = FFuint64(val) diff --git a/pkg/fftypes/jsonobject.go b/pkg/fftypes/jsonobject.go index 4598dbf..ec06bbb 100644 --- a/pkg/fftypes/jsonobject.go +++ b/pkg/fftypes/jsonobject.go @@ -110,7 +110,7 @@ func (jd JSONObject) GetStringOk(key string) (string, bool) { case int64: return strconv.FormatInt(vt, 10), true case uint: - return strconv.FormatInt(int64(vt), 10), true + return strconv.FormatUint(uint64(vt), 10), true case uint8: return strconv.FormatInt(int64(vt), 10), true case uint16: @@ -118,7 +118,7 @@ func (jd JSONObject) GetStringOk(key string) (string, bool) { case uint32: return strconv.FormatInt(int64(vt), 10), true case uint64: - return strconv.FormatInt(int64(vt), 10), true + return strconv.FormatUint(vt, 10), true case nil: return "", false // no need to log for nil default: diff --git a/pkg/fftypes/uuid.go b/pkg/fftypes/uuid.go index 093a584..594877c 100644 --- a/pkg/fftypes/uuid.go +++ b/pkg/fftypes/uuid.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -93,12 +93,12 @@ func (u *UUID) UnmarshalBinary(b []byte) error { } func (u *UUID) HashBucket(buckets int) int { - if u == nil { + if u == nil || buckets <= 0 { return 0 } // Take the last random 4 bytes and mod it against the bucket count to generate // a deterministic hash bucket allocation for the UUID V4 - return int(binary.BigEndian.Uint64((*u)[8:]) % uint64(buckets)) + return int(binary.BigEndian.Uint16((*u)[8:])) % buckets } diff --git a/pkg/fftypes/uuid_test.go b/pkg/fftypes/uuid_test.go index d0c3a4e..af2301e 100644 --- a/pkg/fftypes/uuid_test.go +++ b/pkg/fftypes/uuid_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -93,6 +93,8 @@ func TestHashBucket(t *testing.T) { assert.Equal(t, 0, u3.HashBucket(2)) assert.Equal(t, 0, ((*UUID)(nil)).HashBucket(12345)) + assert.Equal(t, 0, u3.HashBucket(-1)) + assert.Equal(t, 0, u3.HashBucket(0)) } diff --git a/pkg/i18n/errors.go b/pkg/i18n/errors.go index 390ef88..5a3dc74 100644 --- a/pkg/i18n/errors.go +++ b/pkg/i18n/errors.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -82,7 +82,7 @@ func ffWrap(err error, msgKey ErrorMessageKey) error { // NewError creates a new error func NewError(ctx context.Context, msg ErrorMessageKey, inserts ...interface{}) error { - return ffWrap(errors.Errorf(truncate(ExpandWithCode(ctx, MessageKey(msg), inserts...), 2048)), msg) + return ffWrap(errors.New(truncate(ExpandWithCode(ctx, MessageKey(msg), inserts...), 2048)), msg) } // WrapError wraps an error diff --git a/pkg/metric/prometheusMetricsManager.go b/pkg/metric/prometheusMetricsManager.go index 33071f8..191b4d9 100644 --- a/pkg/metric/prometheusMetricsManager.go +++ b/pkg/metric/prometheusMetricsManager.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -50,7 +50,7 @@ func checkAndUpdateLabelNames(ctx context.Context, labelNames []string, withDefa for _, labelName := range labelNames { if strings.HasPrefix(labelName, fireflySystemLabelsPrefix) { err := i18n.NewError(ctx, i18n.MsgMetricsInvalidLabel, labelName, fireflySystemLabelsPrefix) - log.L(ctx).Errorf(err.Error()) + log.L(ctx).Error(err.Error()) } else { validLabelNames = append(validLabelNames, labelName) } diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 02e0ba1..481507b 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -1,5 +1,18 @@ -// Kaleido, Inc. CONFIDENTIAL -// Unpublished Copyright © 2023 Kaleido, Inc. All Rights Reserved. +// Copyright © 2024 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package version diff --git a/pkg/wsclient/wsclient.go b/pkg/wsclient/wsclient.go index bc4f846..a1df7f9 100644 --- a/pkg/wsclient/wsclient.go +++ b/pkg/wsclient/wsclient.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 //