Skip to content

Commit 0e99e64

Browse files
authoredAug 26, 2023
Update golangci-lint and gosec (#1609)
1 parent 6aea1e0 commit 0e99e64

File tree

10 files changed

+32
-13
lines changed

10 files changed

+32
-13
lines changed
 

‎.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ jobs:
1616
- name: Run golangci-lint
1717
uses: golangci/golangci-lint-action@v3
1818
with:
19-
version: v1.51.1
19+
version: v1.54.2
2020
args: --enable=nolintlint,gochecknoinits,bodyclose,gofumpt --verbose

‎.github/workflows/security.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Run Gosec Security Scanner
19-
uses: securego/gosec@v2.14.0
19+
uses: securego/gosec@v2.17.0
2020
with:
2121
args: '-exclude=G104,G304,G402 ./...'

‎b2s_old.go

-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ import "unsafe"
1111
// Note it may break if string and/or slice header will change
1212
// in the future go versions.
1313
func b2s(b []byte) string {
14-
/* #nosec G103 */
1514
return *(*string)(unsafe.Pointer(&b))
1615
}

‎client.go

+1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ func (c *Client) mCleaner(m map[string]*HostClient) {
581581
c.mLock.Lock()
582582
for k, v := range m {
583583
v.connsLock.Lock()
584+
/* #nosec G601 */
584585
if v.connsCount == 0 && atomic.LoadInt32(&v.pendingClientRequests) == 0 {
585586
delete(m, k)
586587
}

‎fasthttpadaptor/b2s_new.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build go1.20
2+
// +build go1.20
3+
4+
package fasthttpadaptor
5+
6+
import "unsafe"
7+
8+
// b2s converts byte slice to a string without memory allocation.
9+
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
10+
func b2s(b []byte) string {
11+
return unsafe.String(unsafe.SliceData(b), len(b))
12+
}

‎fasthttpadaptor/b2s_old.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build !go1.20
2+
// +build !go1.20
3+
4+
package fasthttpadaptor
5+
6+
import "unsafe"
7+
8+
// b2s converts byte slice to a string without memory allocation.
9+
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
10+
//
11+
// Note it may break if string and/or slice header will change
12+
// in the future go versions.
13+
func b2s(b []byte) string {
14+
return *(*string)(unsafe.Pointer(&b))
15+
}

‎fasthttpadaptor/request.go

-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io"
66
"net/http"
77
"net/url"
8-
"unsafe"
98

109
"github.com/valyala/fasthttp"
1110
)
@@ -65,8 +64,3 @@ func ConvertRequest(ctx *fasthttp.RequestCtx, r *http.Request, forServer bool) e
6564

6665
return nil
6766
}
68-
69-
func b2s(b []byte) string {
70-
/* #nosec G103 */
71-
return *(*string)(unsafe.Pointer(&b))
72-
}

‎headers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const (
136136

137137
// WebSockets
138138
HeaderSecWebSocketAccept = "Sec-WebSocket-Accept"
139-
HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions"
139+
HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" /* #nosec G101 */
140140
HeaderSecWebSocketKey = "Sec-WebSocket-Key"
141141
HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol"
142142
HeaderSecWebSocketVersion = "Sec-WebSocket-Version"

‎lbclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (cc *LBClient) get() *lbClient {
138138
minT := atomic.LoadUint64(&minC.total)
139139
for _, c := range cs[1:] {
140140
n := c.PendingRequests()
141-
t := atomic.LoadUint64(&c.total)
141+
t := atomic.LoadUint64(&c.total) /* #nosec G601 */
142142
if n < minN || (n == minN && t < minT) {
143143
minC = c
144144
minN = n

‎s2b_old.go

-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313
// Note it may break if string and/or slice header will change
1414
// in the future go versions.
1515
func s2b(s string) (b []byte) {
16-
/* #nosec G103 */
1716
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
18-
/* #nosec G103 */
1917
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
2018
bh.Data = sh.Data
2119
bh.Cap = sh.Len

0 commit comments

Comments
 (0)
Please sign in to comment.