mirror of
https://github.com/qdm12/gluetun.git
synced 2026-08-06 12:23:31 +02:00
chore(lint): bump linter from v2.4.0 to v2.11.4
This commit is contained in:
@@ -46,6 +46,7 @@ linters:
|
|||||||
- dupl
|
- dupl
|
||||||
- err113
|
- err113
|
||||||
- maintidx
|
- maintidx
|
||||||
|
- prealloc
|
||||||
path: _test\.go
|
path: _test\.go
|
||||||
- linters:
|
- linters:
|
||||||
- dupl
|
- dupl
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ ARG ALPINE_VERSION=3.23
|
|||||||
ARG GO_ALPINE_VERSION=3.23
|
ARG GO_ALPINE_VERSION=3.23
|
||||||
ARG GO_VERSION=1.25
|
ARG GO_VERSION=1.25
|
||||||
ARG XCPUTRANSLATE_VERSION=v0.9.0
|
ARG XCPUTRANSLATE_VERSION=v0.9.0
|
||||||
ARG GOLANGCI_LINT_VERSION=v2.4.0
|
ARG GOLANGCI_LINT_VERSION=v2.11.4
|
||||||
ARG MOCKGEN_VERSION=v0.6.0
|
ARG MOCKGEN_VERSION=v0.6.0
|
||||||
ARG BUILDPLATFORM=linux/amd64
|
ARG BUILDPLATFORM=linux/amd64
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func (c *ControlServer) setDefaults() {
|
|||||||
var role auth.Role
|
var role auth.Role
|
||||||
_ = json.Unmarshal([]byte(c.AuthDefaultRole), &role)
|
_ = json.Unmarshal([]byte(c.AuthDefaultRole), &role)
|
||||||
role.Name = "default"
|
role.Name = "default"
|
||||||
roleBytes, _ := json.Marshal(role) //nolint:errchkjson
|
roleBytes, _ := json.Marshal(role) //nolint:errchkjson,gosec
|
||||||
c.AuthDefaultRole = string(roleBytes)
|
c.AuthDefaultRole = string(roleBytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func (s *Server) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
ReadTimeout: readTimeout,
|
ReadTimeout: readTimeout,
|
||||||
}
|
}
|
||||||
serverDone := make(chan struct{})
|
serverDone := make(chan struct{})
|
||||||
go func() {
|
go func() { //nolint:gosec
|
||||||
defer close(serverDone)
|
defer close(serverDone)
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
const shutdownGraceDuration = 2 * time.Second
|
const shutdownGraceDuration = 2 * time.Second
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (h *handler) handleHTTP(responseWriter http.ResponseWriter, request *http.R
|
|||||||
setForwardedHeaders(request)
|
setForwardedHeaders(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := h.client.Do(request)
|
response, err := h.client.Do(request) //nolint:gosec // SSRF is the feature: HTTP proxy forwards to arbitrary URLs
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(responseWriter, "server error", http.StatusInternalServerError)
|
http.Error(responseWriter, "server error", http.StatusInternalServerError)
|
||||||
h.logger.Warn("cannot process request for client " + request.RemoteAddr + ": " + err.Error())
|
h.logger.Warn("cannot process request for client " + request.RemoteAddr + ": " + err.Error())
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (s *Server) Run(ctx context.Context, errorCh chan<- error) {
|
|||||||
ReadHeaderTimeout: s.readHeaderTimeout,
|
ReadHeaderTimeout: s.readHeaderTimeout,
|
||||||
ReadTimeout: s.readTimeout,
|
ReadTimeout: s.readTimeout,
|
||||||
}
|
}
|
||||||
go func() {
|
go func() { //nolint:gosec
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
const shutdownGraceDuration = 100 * time.Millisecond
|
const shutdownGraceDuration = 100 * time.Millisecond
|
||||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), shutdownGraceDuration)
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), shutdownGraceDuration)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func (s *Server) Run(ctx context.Context, ready chan<- struct{}, done chan<- str
|
|||||||
crashed := make(chan struct{})
|
crashed := make(chan struct{})
|
||||||
shutdownDone := make(chan struct{})
|
shutdownDone := make(chan struct{})
|
||||||
listenCtx, listenCancel := context.WithCancel(ctx)
|
listenCtx, listenCancel := context.WithCancel(ctx)
|
||||||
go func() {
|
go func() { //nolint:gosec
|
||||||
defer close(shutdownDone)
|
defer close(shutdownDone)
|
||||||
defer listenCancel()
|
defer listenCancel()
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func initModule(path string) (err error) {
|
|||||||
default:
|
default:
|
||||||
const moduleParams = ""
|
const moduleParams = ""
|
||||||
const flags = 0
|
const flags = 0
|
||||||
err = unix.FinitModule(int(file.Fd()), moduleParams, flags)
|
err = unix.FinitModule(int(file.Fd()), moduleParams, flags) //nolint:gosec
|
||||||
switch {
|
switch {
|
||||||
case err == nil, err == unix.EEXIST: //nolint:err113
|
case err == nil, err == unix.EEXIST: //nolint:err113
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (c cipherDESCBC) Encrypt(key, iv, plaintext []byte) ([]byte, error) {
|
|||||||
ciphertext := make([]byte, len(plaintext)+paddingLen)
|
ciphertext := make([]byte, len(plaintext)+paddingLen)
|
||||||
copy(ciphertext, plaintext)
|
copy(ciphertext, plaintext)
|
||||||
copy(ciphertext[len(plaintext):],
|
copy(ciphertext[len(plaintext):],
|
||||||
bytes.Repeat([]byte{byte(paddingLen)}, paddingLen))
|
bytes.Repeat([]byte{byte(paddingLen)}, paddingLen)) //nolint:gosec
|
||||||
blockEncrypter.CryptBlocks(ciphertext, ciphertext)
|
blockEncrypter.CryptBlocks(ciphertext, ciphertext)
|
||||||
return ciphertext, nil
|
return ciphertext, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ func start(ctx context.Context, starter CmdStarter, version string, flags []stri
|
|||||||
return nil, nil, nil, fmt.Errorf("OpenVPN version is unknown: %s", version)
|
return nil, nil, nil, fmt.Errorf("OpenVPN version is unknown: %s", version)
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{"--config", configPath}
|
args := make([]string, 0, 2+len(flags)) //nolint:mnd
|
||||||
|
args = append(args, "--config", configPath)
|
||||||
args = append(args, flags...)
|
args = append(args, flags...)
|
||||||
cmd := exec.CommandContext(ctx, bin, args...)
|
cmd := exec.CommandContext(ctx, bin, args...)
|
||||||
setCmdSysProcAttr(cmd)
|
setCmdSysProcAttr(cmd)
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func setDontFragment(fd uintptr, ipv4 bool) (err error) {
|
func setDontFragment(fd uintptr, ipv4 bool) (err error) {
|
||||||
|
fdInt := int(fd) //nolint:gosec
|
||||||
if ipv4 {
|
if ipv4 {
|
||||||
return unix.SetsockoptInt(int(fd), unix.IPPROTO_IP,
|
return unix.SetsockoptInt(fdInt, unix.IPPROTO_IP,
|
||||||
unix.IP_MTU_DISCOVER, unix.IP_PMTUDISC_PROBE)
|
unix.IP_MTU_DISCOVER, unix.IP_PMTUDISC_PROBE)
|
||||||
}
|
}
|
||||||
return unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6,
|
return unix.SetsockoptInt(fdInt, unix.IPPROTO_IPV6,
|
||||||
unix.IPV6_MTU_DISCOVER, unix.IPV6_PMTUDISC_PROBE)
|
unix.IPV6_MTU_DISCOVER, unix.IPV6_PMTUDISC_PROBE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func ipChecksum(header []byte) uint16 {
|
|||||||
for (sum >> 16) > 0 {
|
for (sum >> 16) > 0 {
|
||||||
sum = (sum & 0xFFFF) + (sum >> 16)
|
sum = (sum & 0xFFFF) + (sum >> 16)
|
||||||
}
|
}
|
||||||
return ^uint16(sum) //nolint:gosec
|
return ^uint16(sum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HeaderV6 makes an IPv6 header.
|
// HeaderV6 makes an IPv6 header.
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func tcpChecksum(ipHeader, tcpHeader, payload []byte) uint16 {
|
|||||||
for (sum >> 16) > 0 {
|
for (sum >> 16) > 0 {
|
||||||
sum = (sum & 0xFFFF) + (sum >> 16)
|
sum = (sum & 0xFFFF) + (sum >> 16)
|
||||||
}
|
}
|
||||||
return ^uint16(sum) //nolint:gosec
|
return ^uint16(sum)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func Test_Server(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
go func(client *http.Client, request *http.Request, results chan<- httpResult) {
|
go func(client *http.Client, request *http.Request, results chan<- httpResult) {
|
||||||
response, err := client.Do(request) //nolint:bodyclose
|
response, err := client.Do(request) //nolint:bodyclose,gosec // test code accessing local pprof server
|
||||||
results <- httpResult{
|
results <- httpResult{
|
||||||
url: request.URL.String(),
|
url: request.URL.String(),
|
||||||
response: response,
|
response: response,
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ func (c *apiClient) cookieToken(ctx context.Context, sessionID, tokenType, acces
|
|||||||
|
|
||||||
buffer := bytes.NewBuffer(nil)
|
buffer := bytes.NewBuffer(nil)
|
||||||
encoder := json.NewEncoder(buffer)
|
encoder := json.NewEncoder(buffer)
|
||||||
if err := encoder.Encode(requestBody); err != nil {
|
if err := encoder.Encode(requestBody); err != nil { //nolint:gosec
|
||||||
return "", fmt.Errorf("encoding request body: %w", err)
|
return "", fmt.Errorf("encoding request body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +536,7 @@ func httpHeadersToString(headers http.Header) string {
|
|||||||
if !first {
|
if !first {
|
||||||
builder.WriteString(", ")
|
builder.WriteString(", ")
|
||||||
}
|
}
|
||||||
builder.WriteString(fmt.Sprintf("%s: %s", key, value))
|
fmt.Fprintf(&builder, "%s: %s", key, value)
|
||||||
first = false
|
first = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ func connectSourceConnection(ctx context.Context, fd int, destinationAddrPort ne
|
|||||||
return nil, fmt.Errorf("connecting socket: %w", err)
|
return nil, fmt.Errorf("connecting socket: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
file := os.NewFile(uintptr(fd), "")
|
file := os.NewFile(uintptr(fd), "") //nolint:gosec
|
||||||
if file == nil {
|
if file == nil {
|
||||||
closeFD(fd)
|
closeFD(fd)
|
||||||
return nil, fmt.Errorf("creating socket file for destination %s", destinationAddrPort)
|
return nil, fmt.Errorf("creating socket file for destination %s", destinationAddrPort)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func connectFD(ctx context.Context, fd int, destination netip.AddrPort) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getsockopt error: %w", err)
|
return fmt.Errorf("getsockopt error: %w", err)
|
||||||
} else if n != 0 {
|
} else if n != 0 {
|
||||||
return fmt.Errorf("connect failed asynchronously: %w", unix.Errno(n))
|
return fmt.Errorf("connect failed asynchronously: %w", unix.Errno(n)) //nolint:gosec
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func (h *openvpnHandler) getSettings(w http.ResponseWriter) {
|
|||||||
vpnSettings := h.looper.GetSettings()
|
vpnSettings := h.looper.GetSettings()
|
||||||
settings := vpnSettings.OpenVPN
|
settings := vpnSettings.OpenVPN
|
||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
if err := encoder.Encode(settings); err != nil {
|
if err := encoder.Encode(settings); err != nil { //nolint:gosec
|
||||||
h.warner.Warn(err.Error())
|
h.warner.Warn(err.Error())
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func (h *vpnHandler) patchSettings(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
outcome := h.looper.SetSettings(h.ctx, updatedSettings)
|
outcome := h.looper.SetSettings(h.ctx, updatedSettings)
|
||||||
_, err = w.Write([]byte(outcome))
|
_, err = w.Write([]byte(outcome)) //nolint:gosec // internal API writes status outcome, not HTML rendered in browser
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.warner.Warn("writing response: " + err.Error())
|
h.warner.Warn("writing response: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func encodeBindData(addrType addrType, address string, port uint16) (
|
|||||||
if len(address) > maxDomainNameLength {
|
if len(address) > maxDomainNameLength {
|
||||||
return nil, fmt.Errorf("%w: %s", ErrDomainNameTooLong, address)
|
return nil, fmt.Errorf("%w: %s", ErrDomainNameTooLong, address)
|
||||||
}
|
}
|
||||||
data = append(data, byte(len(address)))
|
data = append(data, byte(len(address))) //nolint:gosec
|
||||||
data = append(data, []byte(address)...)
|
data = append(data, []byte(address)...)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unsupported address type %d", addrType))
|
panic(fmt.Sprintf("unsupported address type %d", addrType))
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (s *server) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) Start(ctx context.Context) (runErr <-chan error, err error) {
|
func (s *server) Start(ctx context.Context) (runErr <-chan error, err error) {
|
||||||
s.socksConnCtx, s.socksConnCancel = context.WithCancel(context.Background())
|
s.socksConnCtx, s.socksConnCancel = context.WithCancel(context.Background()) //nolint:gosec
|
||||||
config := &net.ListenConfig{}
|
config := &net.ListenConfig{}
|
||||||
s.tcpListener, err = config.Listen(ctx, "tcp", s.address)
|
s.tcpListener, err = config.Listen(ctx, "tcp", s.address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ func dialSOCKS5(t *testing.T, proxyAddr, targetAddr, username, password string)
|
|||||||
connectRequest = []byte{socks5Version, byte(connect), 0, byte(ipv4)}
|
connectRequest = []byte{socks5Version, byte(connect), 0, byte(ipv4)}
|
||||||
connectRequest = append(connectRequest, ip...)
|
connectRequest = append(connectRequest, ip...)
|
||||||
} else {
|
} else {
|
||||||
connectRequest = []byte{socks5Version, byte(connect), 0, byte(domainName), byte(len(host))}
|
connectRequest = []byte{socks5Version, byte(connect), 0, byte(domainName), byte(len(host))} //nolint:gosec
|
||||||
connectRequest = append(connectRequest, []byte(host)...)
|
connectRequest = append(connectRequest, []byte(host)...)
|
||||||
}
|
}
|
||||||
connectRequest = binary.BigEndian.AppendUint16(connectRequest, uint16(targetPort)) //nolint:gosec
|
connectRequest = binary.BigEndian.AppendUint16(connectRequest, uint16(targetPort)) //nolint:gosec
|
||||||
@@ -350,9 +350,10 @@ func negotiateSOCKS5(t *testing.T, conn net.Conn, username, password string) {
|
|||||||
require.Equal(t, byte(method), methodResp[1])
|
require.Equal(t, byte(method), methodResp[1])
|
||||||
|
|
||||||
if method == authUsernamePassword {
|
if method == authUsernamePassword {
|
||||||
packet := []byte{authUsernamePasswordSubNegotiation1, byte(len(username))}
|
packet := make([]byte, 0, 2+len(username)+len(password))
|
||||||
|
packet = append(packet, authUsernamePasswordSubNegotiation1, byte(len(username))) //nolint:gosec
|
||||||
packet = append(packet, []byte(username)...)
|
packet = append(packet, []byte(username)...)
|
||||||
packet = append(packet, byte(len(password)))
|
packet = append(packet, byte(len(password))) //nolint:gosec
|
||||||
packet = append(packet, []byte(password)...)
|
packet = append(packet, []byte(password)...)
|
||||||
_, err = conn.Write(packet)
|
_, err = conn.Write(packet)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -443,7 +444,7 @@ func makeSOCKS5UDPDatagram(targetAddress string, payload []byte) ([]byte, error)
|
|||||||
if len(host) > 255 {
|
if len(host) > 255 {
|
||||||
return nil, errors.New("domain name too long")
|
return nil, errors.New("domain name too long")
|
||||||
}
|
}
|
||||||
datagram = append(datagram, byte(domainName), byte(len(host)))
|
datagram = append(datagram, byte(domainName), byte(len(host))) //nolint:gosec
|
||||||
datagram = append(datagram, []byte(host)...)
|
datagram = append(datagram, []byte(host)...)
|
||||||
}
|
}
|
||||||
datagram = binary.BigEndian.AppendUint16(datagram, uint16(port))
|
datagram = binary.BigEndian.AppendUint16(datagram, uint16(port))
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
for stayHere {
|
for stayHere {
|
||||||
select {
|
select {
|
||||||
case <-tunnelReady:
|
case <-tunnelReady:
|
||||||
go l.onTunnelUp(vpnCtx, ctx, tunnelUpData)
|
go l.onTunnelUp(vpnCtx, ctx, tunnelUpData) //nolint:gosec
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
l.cleanup()
|
l.cleanup()
|
||||||
vpnCancel()
|
vpnCancel()
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import (
|
|||||||
// omitted so wireguard-go's initFromFlags sees no vnet header support and
|
// omitted so wireguard-go's initFromFlags sees no vnet header support and
|
||||||
// keeps tun.vnetHdr=false, falling back to simple single-packet writes instead
|
// keeps tun.vnetHdr=false, falling back to simple single-packet writes instead
|
||||||
// of the GRO/GSO batch path that causes EINVAL on some vendor kernels.
|
// of the GRO/GSO batch path that causes EINVAL on some vendor kernels.
|
||||||
func createTUN(name string, mtu int, gso bool) (tun.Device, error) { //nolint:ireturn
|
//
|
||||||
|
//nolint:ireturn
|
||||||
|
func createTUN(name string, mtu int, gso bool) (tun.Device, error) {
|
||||||
if gso {
|
if gso {
|
||||||
return tun.CreateTUN(name, mtu)
|
return tun.CreateTUN(name, mtu)
|
||||||
}
|
}
|
||||||
@@ -49,5 +51,5 @@ func OpenTUNFile(name string) (*os.File, error) {
|
|||||||
unix.Close(tunFD)
|
unix.Close(tunFD)
|
||||||
return nil, fmt.Errorf("setting nonblock: %w", err)
|
return nil, fmt.Errorf("setting nonblock: %w", err)
|
||||||
}
|
}
|
||||||
return os.NewFile(uintptr(tunFD), "/dev/net/tun"), nil
|
return os.NewFile(uintptr(tunFD), "/dev/net/tun"), nil //nolint:gosec
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user