Pull request:* all: fix all staticcheck SA warnings
Merge in DNS/adguard-home from 2238-fix-static-analisys-warnings to master Squashed commit of the following: commit 721ca6fa1cbfdfe9d414e6ed52fec4a64653fb52 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Oct 30 15:48:10 2020 +0300 * all: fix all staticcheck SA warnings Closes #2238.
This commit is contained in:
parent
ae8de95d89
commit
812b43a4b3
|
@ -175,7 +175,7 @@ func (s *Server) handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
v6conf.InterfaceName = newconfig.InterfaceName
|
v6conf.InterfaceName = newconfig.InterfaceName
|
||||||
v6conf.notify = s.onNotify
|
v6conf.notify = s.onNotify
|
||||||
s6, err = v6Create(v6conf)
|
s6, err = v6Create(v6conf)
|
||||||
if s6 == nil {
|
if err != nil {
|
||||||
httpError(r, w, http.StatusBadRequest, "Invalid DHCPv6 configuration: %s", err)
|
httpError(r, w, http.StatusBadRequest, "Invalid DHCPv6 configuration: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,6 @@ func TestIsValidSubnetMask(t *testing.T) {
|
||||||
func TestNormalizeLeases(t *testing.T) {
|
func TestNormalizeLeases(t *testing.T) {
|
||||||
dynLeases := []*Lease{}
|
dynLeases := []*Lease{}
|
||||||
staticLeases := []*Lease{}
|
staticLeases := []*Lease{}
|
||||||
leases := []*Lease{}
|
|
||||||
|
|
||||||
lease := &Lease{}
|
lease := &Lease{}
|
||||||
lease.HWAddr = []byte{1, 2, 3, 4}
|
lease.HWAddr = []byte{1, 2, 3, 4}
|
||||||
|
@ -100,7 +99,7 @@ func TestNormalizeLeases(t *testing.T) {
|
||||||
lease.HWAddr = []byte{2, 2, 3, 4}
|
lease.HWAddr = []byte{2, 2, 3, 4}
|
||||||
staticLeases = append(staticLeases, lease)
|
staticLeases = append(staticLeases, lease)
|
||||||
|
|
||||||
leases = normalizeLeases(staticLeases, dynLeases)
|
leases := normalizeLeases(staticLeases, dynLeases)
|
||||||
|
|
||||||
assert.True(t, len(leases) == 3)
|
assert.True(t, len(leases) == 3)
|
||||||
assert.True(t, bytes.Equal(leases[0].HWAddr, []byte{1, 2, 3, 4}))
|
assert.True(t, bytes.Equal(leases[0].HWAddr, []byte{1, 2, 3, 4}))
|
||||||
|
|
|
@ -45,6 +45,7 @@ func ip6InRange(start net.IP, ip net.IP) bool {
|
||||||
if len(start) != 16 {
|
if len(start) != 16 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
//lint:ignore SA1021 TODO(e.burkov): Ignore this for now, think about using masks.
|
||||||
if !bytes.Equal(start[:15], ip[:15]) {
|
if !bytes.Equal(start[:15], ip[:15]) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -815,12 +815,13 @@ func sendTestMessageAsync(t *testing.T, conn *dns.Conn, g *sync.WaitGroup) {
|
||||||
req := createGoogleATestMessage()
|
req := createGoogleATestMessage()
|
||||||
err := conn.WriteMsg(req)
|
err := conn.WriteMsg(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot write message: %s", err)
|
panic(fmt.Sprintf("cannot write message: %s", err))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := conn.ReadMsg()
|
res, err := conn.ReadMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot read response to message: %s", err)
|
panic(fmt.Sprintf("cannot read response to message: %s", err))
|
||||||
}
|
}
|
||||||
assertGoogleAResponse(t, res)
|
assertGoogleAResponse(t, res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,8 +306,7 @@ func verifyCertChain(data *tlsConfigStatus, certChain string, serverName string)
|
||||||
log.Tracef("TLS: got certificate: %d bytes", len(certChain))
|
log.Tracef("TLS: got certificate: %d bytes", len(certChain))
|
||||||
|
|
||||||
// now do a more extended validation
|
// now do a more extended validation
|
||||||
var certs []*pem.Block // PEM-encoded certificates
|
var certs []*pem.Block // PEM-encoded certificates
|
||||||
var skippedBytes []string // skipped bytes
|
|
||||||
|
|
||||||
pemblock := []byte(certChain)
|
pemblock := []byte(certChain)
|
||||||
for {
|
for {
|
||||||
|
@ -318,10 +317,6 @@ func verifyCertChain(data *tlsConfigStatus, certChain string, serverName string)
|
||||||
}
|
}
|
||||||
if decoded.Type == "CERTIFICATE" {
|
if decoded.Type == "CERTIFICATE" {
|
||||||
certs = append(certs, decoded)
|
certs = append(certs, decoded)
|
||||||
} else {
|
|
||||||
// ignore "this result of append is never used" warning
|
|
||||||
// nolint
|
|
||||||
skippedBytes = append(skippedBytes, decoded.Type)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,8 +382,7 @@ func verifyCertChain(data *tlsConfigStatus, certChain string, serverName string)
|
||||||
|
|
||||||
func validatePkey(data *tlsConfigStatus, pkey string) error {
|
func validatePkey(data *tlsConfigStatus, pkey string) error {
|
||||||
// now do a more extended validation
|
// now do a more extended validation
|
||||||
var key *pem.Block // PEM-encoded certificates
|
var key *pem.Block // PEM-encoded certificates
|
||||||
var skippedBytes []string // skipped bytes
|
|
||||||
|
|
||||||
// go through all pem blocks, but take first valid pem block and drop the rest
|
// go through all pem blocks, but take first valid pem block and drop the rest
|
||||||
pemblock := []byte(pkey)
|
pemblock := []byte(pkey)
|
||||||
|
@ -401,10 +395,6 @@ func validatePkey(data *tlsConfigStatus, pkey string) error {
|
||||||
if decoded.Type == "PRIVATE KEY" || strings.HasSuffix(decoded.Type, " PRIVATE KEY") {
|
if decoded.Type == "PRIVATE KEY" || strings.HasSuffix(decoded.Type, " PRIVATE KEY") {
|
||||||
key = decoded
|
key = decoded
|
||||||
break
|
break
|
||||||
} else {
|
|
||||||
// ignore "this result of append is never used"
|
|
||||||
// nolint
|
|
||||||
skippedBytes = append(skippedBytes, decoded.Type)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestJSON(t *testing.T) {
|
||||||
assert.Equal(t, "keystr", k)
|
assert.Equal(t, "keystr", k)
|
||||||
assert.Equal(t, "val", v)
|
assert.Equal(t, "val", v)
|
||||||
|
|
||||||
k, v, jtype = readJSON(&s)
|
k, _, jtype = readJSON(&s)
|
||||||
assert.Equal(t, jtype, int32(jsonTObj))
|
assert.Equal(t, jtype, int32(jsonTObj))
|
||||||
assert.Equal(t, "obj", k)
|
assert.Equal(t, "obj", k)
|
||||||
|
|
||||||
|
@ -29,6 +29,6 @@ func TestJSON(t *testing.T) {
|
||||||
assert.Equal(t, "keyint", k)
|
assert.Equal(t, "keyint", k)
|
||||||
assert.Equal(t, "123456", v)
|
assert.Equal(t, "123456", v)
|
||||||
|
|
||||||
k, v, jtype = readJSON(&s)
|
_, _, jtype = readJSON(&s)
|
||||||
assert.True(t, jtype == jsonTErr)
|
assert.True(t, jtype == jsonTErr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ package util
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
@ -94,14 +95,11 @@ func PProfRegisterWebHandlers(mux *http.ServeMux) {
|
||||||
func Cmdline(w http.ResponseWriter, r *http.Request) {
|
func Cmdline(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
fmt.Fprintf(w, strings.Join(os.Args, "\x00"))
|
fmt.Fprint(w, strings.Join(os.Args, "\x00"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func sleep(w http.ResponseWriter, d time.Duration) {
|
func sleep(ctx context.Context, d time.Duration) {
|
||||||
var clientGone <-chan bool
|
clientGone := ctx.Done()
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
clientGone = cn.CloseNotify()
|
|
||||||
}
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(d):
|
case <-time.After(d):
|
||||||
case <-clientGone:
|
case <-clientGone:
|
||||||
|
@ -146,7 +144,7 @@ func Profile(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Sprintf("Could not enable CPU profiling: %s", err))
|
fmt.Sprintf("Could not enable CPU profiling: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sleep(w, time.Duration(sec)*time.Second)
|
sleep(r.Context(), time.Duration(sec)*time.Second)
|
||||||
pprof.StopCPUProfile()
|
pprof.StopCPUProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +173,7 @@ func Trace(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Sprintf("Could not enable tracing: %s", err))
|
fmt.Sprintf("Could not enable tracing: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sleep(w, time.Duration(sec*float64(time.Second)))
|
sleep(r.Context(), time.Duration(sec*float64(time.Second)))
|
||||||
trace.Stop()
|
trace.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue