Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend, cli: fix vulnerability issues scanned by third-party tools #623

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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