Skip to content

Commit

Permalink
fix: linter issues and examples import
Browse files Browse the repository at this point in the history
  • Loading branch information
savsgio committed Oct 17, 2023
1 parent 4961549 commit 8d87abe
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ jobs:
if: matrix.os == 'ubuntu-latest'
uses: securego/gosec@master
with:
args: -exclude-dir examples ./...
args: -exclude-dir _examples ./...

- name: Run GoVulnCheck
if: matrix.go-version != '1.17.x' && matrix.go-version != '1.18.x'
uses: golang/govulncheck-action@v1
with:
go-version-input: ${{ matrix.go-version }}
Expand Down
2 changes: 1 addition & 1 deletion _examples/bufferpool/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"sync"
"time"

"github.com/gorilla/websocket"
"github.com/fasthttp/websocket"
)

var addr = flag.String("addr", "localhost:8080", "http service address")
Expand Down
2 changes: 1 addition & 1 deletion _examples/bufferpool/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

_ "net/http/pprof"

"github.com/gorilla/websocket"
"github.com/fasthttp/websocket"
)

var addr = flag.String("addr", "localhost:8080", "http service address")
Expand Down
7 changes: 4 additions & 3 deletions mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func maskBytes(key [4]byte, pos int, b []byte) int {
}

// Mask one byte at a time to word boundary.
//#nosec G103 -- (CWE-242) Has been audited
if n := int(uintptr(unsafe.Pointer(&b[0]))) % wordSize; n != 0 {
// #nosec G103 -- (CWE-242) Has been audited
n := int(uintptr(unsafe.Pointer(&b[0]))) % wordSize
if n != 0 {
n = wordSize - n
for i := range b[:n] {
b[i] ^= key[pos&3]
Expand All @@ -42,7 +43,7 @@ func maskBytes(key [4]byte, pos int, b []byte) int {
kw := *(*uintptr)(unsafe.Pointer(&k))

// Mask one word at a time.
n := (len(b) / wordSize) * wordSize
n = (len(b) / wordSize) * wordSize
for i := 0; i < n; i += wordSize {
//#nosec G103 -- (CWE-242) Has been audited
*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i))) ^= kw
Expand Down
11 changes: 5 additions & 6 deletions server_fasthttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ var strPermessageDeflate = []byte("permessage-deflate")

var poolWriteBuffer = sync.Pool{
New: func() interface{} {
var buf []byte
return buf
return new(writePoolData)
},
}

Expand Down Expand Up @@ -183,9 +182,9 @@ func (u *FastHTTPUpgrader) Upgrade(ctx *fasthttp.RequestCtx, handler FastHTTPHan

ctx.Hijack(func(netConn net.Conn) {
// var br *bufio.Reader // Always nil
writeBuf := poolWriteBuffer.Get().([]byte)
writeBuf := poolWriteBuffer.Get().(*writePoolData)

c := newConn(netConn, true, u.ReadBufferSize, u.WriteBufferSize, u.WriteBufferPool, nil, writeBuf)
c := newConn(netConn, true, u.ReadBufferSize, u.WriteBufferSize, u.WriteBufferPool, nil, writeBuf.buf)
if subprotocol != nil {
c.subprotocol = strconv.B2S(subprotocol)
}
Expand All @@ -196,11 +195,11 @@ func (u *FastHTTPUpgrader) Upgrade(ctx *fasthttp.RequestCtx, handler FastHTTPHan
}

// Clear deadlines set by HTTP server.
netConn.SetDeadline(time.Time{})
_ = netConn.SetDeadline(time.Time{})

handler(c)

writeBuf = writeBuf[0:0]
writeBuf.buf = writeBuf.buf[0:0]
poolWriteBuffer.Put(writeBuf)
})

Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func computeAcceptKey(challengeKey string) string {
}

func computeAcceptKeyBytes(challengeKey []byte) string {
h := sha1.New()
h := sha1.New() //#nosec G401 -- (CWE-326) https://datatracker.ietf.org/doc/html/rfc6455#page-54
h.Write(challengeKey)
h.Write(keyGUID)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
Expand Down

0 comments on commit 8d87abe

Please sign in to comment.