File tree Expand file tree Collapse file tree 9 files changed +60
-20
lines changed Expand file tree Collapse file tree 9 files changed +60
-20
lines changed Original file line number Diff line number Diff line change 1+ name : gosec
2+ on :
3+ push :
4+ tags :
5+ - v*
6+ branches :
7+ - master
8+ - ' **'
9+ pull_request :
10+ workflow_dispatch :
11+ jobs :
12+ tests :
13+ runs-on : ubuntu-latest
14+ env :
15+ GO111MODULE : on
16+ steps :
17+ - name : Checkout Source
18+ uses : actions/checkout@v2
19+ - name : Run Gosec Security Scanner
20+ uses : securego/gosec@master
21+ with :
22+ args : ./...
Original file line number Diff line number Diff line change @@ -300,7 +300,8 @@ func defaults() (c *config) {
300300 discoveryInterval : DefaultDiscoveryInterval ,
301301 balancingConfig : DefaultBalancer ,
302302 tlsConfig : & tls.Config {
303- RootCAs : certPool ,
303+ MinVersion : tls .VersionTLS12 ,
304+ RootCAs : certPool ,
304305 },
305306 }
306307}
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ package balancer
22
33import (
44 "errors"
5- "math/rand"
6- "time"
75
86 "github.com/ydb-platform/ydb-go-sdk/v3/config"
97 "github.com/ydb-platform/ydb-go-sdk/v3/internal/driver/cluster/balancer/conn"
@@ -48,19 +46,15 @@ type Balancer interface {
4846}
4947
5048func defaultBalancer () Balancer {
51- return & randomChoice {
52- r : rand .New (rand .NewSource (time .Now ().UnixNano ())),
53- }
49+ return & randomChoice {}
5450}
5551
5652func newBalancer (cfg config.BalancerConfig ) Balancer {
5753 switch cfg .Algorithm {
5854 case config .BalancingAlgorithmRoundRobin :
5955 return & roundRobin {}
6056 case config .BalancingAlgorithmRandomChoice :
61- return & randomChoice {
62- r : rand .New (rand .NewSource (time .Now ().UnixNano ())),
63- }
57+ return & randomChoice {}
6458 default :
6559 return defaultBalancer ()
6660 }
Original file line number Diff line number Diff line change @@ -3,14 +3,14 @@ package balancer
33import (
44 "container/heap"
55 "math"
6- "math/rand"
76 "sync"
87 "sync/atomic"
98
109 "github.com/ydb-platform/ydb-go-sdk/v3/internal/driver/cluster/balancer/conn"
1110 "github.com/ydb-platform/ydb-go-sdk/v3/internal/driver/cluster/balancer/conn/info"
1211 "github.com/ydb-platform/ydb-go-sdk/v3/internal/driver/cluster/balancer/conn/list"
1312 "github.com/ydb-platform/ydb-go-sdk/v3/internal/driver/cluster/balancer/state"
13+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/rand"
1414)
1515
1616// roundRobin is an implementation of weighted round-robin balancing algorithm.
@@ -28,7 +28,6 @@ type roundRobin struct {
2828
2929type randomChoice struct {
3030 roundRobin
31- r * rand.Rand // without seed by default
3231 m sync.Mutex
3332}
3433
@@ -46,7 +45,7 @@ func (r *randomChoice) Next() conn.Conn {
4645 return nil
4746 }
4847 r .m .Lock ()
49- i := r .belt [r . r . Intn (len (r .belt ))]
48+ i := r .belt [rand . Int (len (r .belt ))]
5049 r .m .Unlock ()
5150 return r .conns [i ].Conn
5251}
Original file line number Diff line number Diff line change 1+ package rand
2+
3+ import (
4+ "crypto/rand"
5+ "math/big"
6+ )
7+
8+ func int64n (max int64 ) int64 {
9+ n , err := rand .Int (rand .Reader , big .NewInt (max ))
10+ if err != nil {
11+ panic (err ) // err on negative max
12+ }
13+ return n .Int64 ()
14+ }
15+
16+ func Int64 (max int64 ) int64 {
17+ return int64n (max )
18+ }
19+
20+ func Int (max int ) int {
21+ return int (int64n (int64 (max )))
22+ }
Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ func WithCertificatesFromFile(caFile string) Option {
181181 }
182182 caFile = filepath .Join (home , caFile [1 :])
183183 }
184- bytes , err := os .ReadFile (caFile )
184+ bytes , err := os .ReadFile (filepath . Clean ( caFile ) )
185185 if err != nil {
186186 return err
187187 }
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ package retry
33import (
44 "context"
55 "math"
6- "math/rand"
76 "time"
87
98 "github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
9+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/rand"
1010 "github.com/ydb-platform/ydb-go-sdk/v3/trace"
1111)
1212
@@ -155,7 +155,7 @@ func (b logBackoff) delay(i int) time.Duration {
155155 if f == d {
156156 return f
157157 }
158- return f + time .Duration (rand .Intn ( int (d - f )+ 1 ))
158+ return f + time .Duration (rand .Int64 ( int64 (d - f )+ 1 ))
159159}
160160
161161func min (a , b uint ) uint {
Original file line number Diff line number Diff line change 66 "path"
77 "strings"
88
9- "github.com/ydb-platform/ydb-go-sdk/v3"
9+ ydb "github.com/ydb-platform/ydb-go-sdk/v3"
1010 "github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
1111 "github.com/ydb-platform/ydb-go-sdk/v3/scheme"
1212 "github.com/ydb-platform/ydb-go-sdk/v3/table"
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ package testutil
22
33import (
44 "fmt"
5- "math/rand "
5+ "math"
66 "strconv"
7+
8+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/rand"
79)
810
911type (
@@ -23,9 +25,9 @@ func WithServiceID(serviceID uint32) sessionIDOption {
2325
2426func SessionID (opts ... sessionIDOption ) string {
2527 h := & sessionIDHolder {
26- serviceID : rand .Uint32 ( ),
27- nodeID : rand .Uint32 ( ),
28- hash : strconv .FormatUint (rand .Uint64 ( ), 16 ),
28+ serviceID : uint32 ( rand .Int64 ( math . MaxUint32 ) ),
29+ nodeID : uint32 ( rand .Int64 ( math . MaxUint32 ) ),
30+ hash : strconv .FormatInt (rand .Int64 ( math . MaxInt64 ), 16 ),
2931 }
3032 for _ , o := range opts {
3133 o (h )
You can’t perform that action at this time.
0 commit comments