Skip to content

Commit 17b2953

Browse files
committed
fix!: address gosec overflows
BREAKING CHANGE: State consistency, concurrency and operation types are now int32 sized. Panic on an overflow conversion for a proto duration Signed-off-by: Mike Nguyen <[email protected]>
1 parent 24b9679 commit 17b2953

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

client/state.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"errors"
1919
"fmt"
20+
"math"
2021
"time"
2122

2223
"google.golang.org/protobuf/types/known/durationpb"
@@ -65,11 +66,11 @@ const (
6566

6667
type (
6768
// StateConsistency is the consistency enum type.
68-
StateConsistency int
69+
StateConsistency int32
6970
// StateConcurrency is the concurrency enum type.
70-
StateConcurrency int
71+
StateConcurrency int32
7172
// OperationType is the operation enum type.
72-
OperationType int
73+
OperationType int32
7374
)
7475

7576
// GetPBConsistency get consistency pb value.
@@ -252,9 +253,15 @@ func toProtoDuration(d time.Duration) *durationpb.Duration {
252253
nanos := d.Nanoseconds()
253254
secs := nanos / 1e9
254255
nanos -= secs * 1e9
256+
257+
// conversion check - gosec ignored below for conversion
258+
if nanos <= int64(math.MinInt32) && nanos >= int64(math.MaxInt32) {
259+
panic("integer overflow converting duration to proto")
260+
}
261+
255262
return &durationpb.Duration{
256263
Seconds: secs,
257-
Nanos: int32(nanos),
264+
Nanos: int32(nanos), //nolint:gosec
258265
}
259266
}
260267

0 commit comments

Comments
 (0)