Skip to content

Commit

Permalink
backend, cli: fix vulnerability issues scanned by third-party tools (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 authored Aug 5, 2024
1 parent c8d0d82 commit e3d35cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions lib/cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"fmt"
"io"
"math/rand"
"net/http"

"github.com/pingcap/tiproxy/lib/util/errors"
Expand Down Expand Up @@ -39,8 +38,8 @@ func doRequest(ctx context.Context, bctx *Context, method string, url string, rd

var rete string
var res *http.Response
for _, i := range rand.Perm(len(bctx.CUrls)) {
req.URL.Host = bctx.CUrls[i]
for _, url := range bctx.CUrls {
req.URL.Host = url

res, err = bctx.Client.Do(req)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions pkg/proxy/backend/backend_conn_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"sync"
"sync/atomic"
"time"
"unsafe"

"github.com/cenkalti/backoff/v4"
"github.com/go-mysql-org/go-mysql/mysql"
Expand Down Expand Up @@ -123,7 +122,7 @@ type BackendConnManager struct {
signalReceived chan signalType
authenticator *Authenticator
cmdProcessor *CmdProcessor
eventReceiver unsafe.Pointer
eventReceiver atomic.Pointer[router.ConnEventReceiver]
config *BCConfig
logger *zap.Logger
curBackend router.BackendInst
Expand Down Expand Up @@ -406,11 +405,11 @@ func (mgr *BackendConnManager) updateTraffic(backendIO *pnet.PacketIO) {
// SetEventReceiver implements RedirectableConn.SetEventReceiver interface.
// The receiver sends redirection signals and watches redirecting events.
func (mgr *BackendConnManager) SetEventReceiver(receiver router.ConnEventReceiver) {
atomic.StorePointer(&mgr.eventReceiver, unsafe.Pointer(&receiver))
mgr.eventReceiver.Store(&receiver)
}

func (mgr *BackendConnManager) getEventReceiver() router.ConnEventReceiver {
eventReceiver := (*router.ConnEventReceiver)(atomic.LoadPointer(&mgr.eventReceiver))
eventReceiver := mgr.eventReceiver.Load()
if eventReceiver == nil {
return nil
}
Expand Down

0 comments on commit e3d35cb

Please sign in to comment.