mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-05 00:42:56 +08:00
Remove old codacy linter comments
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
@@ -71,7 +71,6 @@ func init() { //nolint:gochecknoinits
|
|||||||
func docsMarkdown(_ *cobra.Command, _ []string, opts *docsOptions) error {
|
func docsMarkdown(_ *cobra.Command, _ []string, opts *docsOptions) error {
|
||||||
dir := filepath.Join(opts.outputDir, "md")
|
dir := filepath.Join(opts.outputDir, "md")
|
||||||
|
|
||||||
//#nosec G301 -- Doc directories must be world readable
|
|
||||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %w", err)
|
return fmt.Errorf("failed to create directory: %w", err)
|
||||||
}
|
}
|
||||||
@@ -123,7 +122,6 @@ func docsMarkdown(_ *cobra.Command, _ []string, opts *docsOptions) error {
|
|||||||
func docsManpage(_ *cobra.Command, _ []string, opts *docsOptions) error {
|
func docsManpage(_ *cobra.Command, _ []string, opts *docsOptions) error {
|
||||||
dir := filepath.Join(opts.outputDir, "man")
|
dir := filepath.Join(opts.outputDir, "man")
|
||||||
|
|
||||||
//#nosec G301 -- Doc directories must be world readable
|
|
||||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %w", err)
|
return fmt.Errorf("failed to create directory: %w", err)
|
||||||
}
|
}
|
||||||
|
@@ -62,7 +62,6 @@ func (p *WireGuardProvider) Read() (map[string]interface{}, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
//#nosec G304 -- Filename is only controlled by user
|
|
||||||
cfgData, err := os.ReadFile(cfg)
|
cfgData, err := os.ReadFile(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open config file %s: %w", cfg, err)
|
return nil, fmt.Errorf("failed to open config file %s: %w", cfg, err)
|
||||||
|
@@ -149,7 +149,6 @@ func (i *Interface) SetDNS(svrs []net.IPAddr, domain []string) error {
|
|||||||
args = append(args, svr.String())
|
args = append(args, svr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
//#nosec G204 -- Filename is only influenced by users PATH variable
|
|
||||||
cmd = exec.Command(resolvectl, args...)
|
cmd = exec.Command(resolvectl, args...)
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
@@ -162,7 +161,6 @@ func (i *Interface) SetDNS(svrs []net.IPAddr, domain []string) error {
|
|||||||
args := []string{"domain", i.Name()}
|
args := []string{"domain", i.Name()}
|
||||||
args = append(args, domain...)
|
args = append(args, domain...)
|
||||||
|
|
||||||
//#nosec G204 -- Filename is only influenced by users PATH variable
|
|
||||||
cmd = exec.Command(resolvectl, args...)
|
cmd = exec.Command(resolvectl, args...)
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
@@ -171,7 +169,6 @@ func (i *Interface) SetDNS(svrs []net.IPAddr, domain []string) error {
|
|||||||
}
|
}
|
||||||
} else if resolveconf, err := exec.LookPath("resolveconf"); err != nil {
|
} else if resolveconf, err := exec.LookPath("resolveconf"); err != nil {
|
||||||
if len(svrs) > 0 || len(domain) > 0 {
|
if len(svrs) > 0 || len(domain) > 0 {
|
||||||
//#nosec G204 -- Filename is only influenced by users PATH variable
|
|
||||||
cmd := exec.Command(resolveconf, "-a", i.Name(), "-m", "0", "-x")
|
cmd := exec.Command(resolveconf, "-a", i.Name(), "-m", "0", "-x")
|
||||||
|
|
||||||
stdin := &bytes.Buffer{}
|
stdin := &bytes.Buffer{}
|
||||||
@@ -200,10 +197,8 @@ func (i *Interface) UnsetDNS() error {
|
|||||||
|
|
||||||
// Check if SystemD's resolvectl is available
|
// Check if SystemD's resolvectl is available
|
||||||
if resolvectl, err := exec.LookPath("resolvectl"); err == nil {
|
if resolvectl, err := exec.LookPath("resolvectl"); err == nil {
|
||||||
//#nosec G204 -- Filename is only influenced by users PATH variable
|
|
||||||
cmd = exec.Command(resolvectl, "revert", i.Name())
|
cmd = exec.Command(resolvectl, "revert", i.Name())
|
||||||
} else if resolveconf, err := exec.LookPath("resolveconf"); err != nil {
|
} else if resolveconf, err := exec.LookPath("resolveconf"); err != nil {
|
||||||
//#nosec G204 -- Filename is only influenced by users PATH variable
|
|
||||||
cmd = exec.Command(resolveconf, "-d", i.Name())
|
cmd = exec.Command(resolveconf, "-d", i.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -92,7 +92,6 @@ func (n *NAT) setupTable(ident string) error {
|
|||||||
// Ignore any previously existing table
|
// Ignore any previously existing table
|
||||||
n.NFConn.DelTable(&nftables.Table{Name: ident})
|
n.NFConn.DelTable(&nftables.Table{Name: ident})
|
||||||
|
|
||||||
//#nosec G104 -- Errors should be ignored here
|
|
||||||
n.NFConn.Flush()
|
n.NFConn.Flush()
|
||||||
|
|
||||||
n.table = n.NFConn.AddTable(&nftables.Table{
|
n.table = n.NFConn.AddTable(&nftables.Table{
|
||||||
|
@@ -23,7 +23,6 @@ func isWritable(fn string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readLines(fn string) ([]string, error) {
|
func readLines(fn string) ([]string, error) {
|
||||||
//#nosec G304 -- Filename is hard coded.
|
|
||||||
f, err := os.OpenFile(fn, os.O_CREATE|os.O_RDONLY, 0o600)
|
f, err := os.OpenFile(fn, os.O_CREATE|os.O_RDONLY, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open file: %w", err)
|
return nil, fmt.Errorf("failed to open file: %w", err)
|
||||||
@@ -44,8 +43,6 @@ func readLines(fn string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeLines(fn string, lines []string) error {
|
func writeLines(fn string, lines []string) error {
|
||||||
//#nosec G302 -- /etc/hosts must be world readable
|
|
||||||
//#nosec G304 -- Filename is hard coded.
|
|
||||||
f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o755)
|
f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open file: %w", err)
|
return fmt.Errorf("failed to open file: %w", err)
|
||||||
|
@@ -204,7 +204,6 @@ func getRouteMTU(ip net.IP) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run(args ...string) (string, error) {
|
func run(args ...string) (string, error) {
|
||||||
//#nosec G204 -- Command is always hardcoded
|
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
@@ -26,7 +26,6 @@ func FindRandomPortToListen(network string, min, max int) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for attempts := 100; attempts > 0; attempts-- {
|
for attempts := 100; attempts > 0; attempts-- {
|
||||||
//#nosec G404 -- Port numbers do not require to be cryptographically random
|
|
||||||
port := min + rand.Intn(max-min+1)
|
port := min + rand.Intn(max-min+1)
|
||||||
if canListenOnPort(network, port) {
|
if canListenOnPort(network, port) {
|
||||||
return port, nil
|
return port, nil
|
||||||
|
@@ -14,7 +14,6 @@ func SetSysctl(name string, value any) error {
|
|||||||
parts := strings.ReplaceAll(name, ".", string(filepath.Separator))
|
parts := strings.ReplaceAll(name, ".", string(filepath.Separator))
|
||||||
path := filepath.Join("/proc/sys", parts)
|
path := filepath.Join("/proc/sys", parts)
|
||||||
|
|
||||||
//#nosec G304 -- Filename is always under /proc/sys
|
|
||||||
f, err := os.OpenFile(path, os.O_WRONLY, 0o600)
|
f, err := os.OpenFile(path, os.O_WRONLY, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -181,13 +181,11 @@ func extractToFile(buf []byte, filename, target string) (int64, error) {
|
|||||||
return -1, fmt.Errorf("failed to remove target file: %w", err)
|
return -1, fmt.Errorf("failed to remove target file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#nosec G304 -- No file inclusion possible as we are writing only.
|
|
||||||
dest, err := os.OpenFile(target, os.O_CREATE|os.O_EXCL|os.O_WRONLY, mode)
|
dest, err := os.OpenFile(target, os.O_CREATE|os.O_EXCL|os.O_WRONLY, mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//#nosec G110 -- We only download from safe locations (GitHub releases)
|
|
||||||
n, err := io.Copy(dest, rd)
|
n, err := io.Copy(dest, rd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = dest.Close()
|
_ = dest.Close()
|
||||||
|
@@ -60,7 +60,6 @@ func ParseURL(urlStr string) (string, []grpc.DialOption, error) {
|
|||||||
if fn := os.Getenv("SSLKEYLOGFILE"); fn != "" {
|
if fn := os.Getenv("SSLKEYLOGFILE"); fn != "" {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
//#nosec G304 -- Filename is only controlled by env var
|
|
||||||
if cfg.KeyLogWriter, err = os.OpenFile(fn, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o600); err != nil {
|
if cfg.KeyLogWriter, err = os.OpenFile(fn, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o600); err != nil {
|
||||||
return "", nil, fmt.Errorf("failed to open SSL keylog file: %w", err)
|
return "", nil, fmt.Errorf("failed to open SSL keylog file: %w", err)
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,6 @@ func NewServer(opts ...grpc.ServerOption) (*grpc.Server, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if fn := os.Getenv("SSLKEYLOGFILE"); fn != "" {
|
if fn := os.Getenv("SSLKEYLOGFILE"); fn != "" {
|
||||||
//#nosec G304 -- Filename is only controlled via env var
|
|
||||||
wr, err := os.OpenFile(fn, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o600)
|
wr, err := os.OpenFile(fn, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open SSL keylog file: %w", err)
|
return nil, fmt.Errorf("failed to open SSL keylog file: %w", err)
|
||||||
|
@@ -91,8 +91,6 @@ func (a *Agent) Start(_, dir string, extraArgs ...any) error {
|
|||||||
return fmt.Errorf("failed to build: %w", err)
|
return fmt.Errorf("failed to build: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#nosec G304 -- Test code is not controllable by attackers
|
|
||||||
//#nosec G302 -- Log file should be readable by user
|
|
||||||
a.logFile, err = os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
|
a.logFile, err = os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open log file: %w", err)
|
return fmt.Errorf("failed to open log file: %w", err)
|
||||||
|
@@ -50,8 +50,6 @@ func (s *GrpcSignalingNode) Start(_, dir string, extraArgs ...any) error {
|
|||||||
return fmt.Errorf("failed to build: %w", err)
|
return fmt.Errorf("failed to build: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#nosec G304 -- Test code is not controllable by attackers
|
|
||||||
//#nosec G302 -- Log file should be readable by user
|
|
||||||
s.logFile, err = os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
|
s.logFile, err = os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open log file: %w", err)
|
return fmt.Errorf("failed to open log file: %w", err)
|
||||||
|
@@ -99,7 +99,6 @@ func (i *WireGuardInterface) WriteConfig() error {
|
|||||||
|
|
||||||
fn := filepath.Join(wgcpath, fmt.Sprintf("%s.conf", i.Name))
|
fn := filepath.Join(wgcpath, fmt.Sprintf("%s.conf", i.Name))
|
||||||
|
|
||||||
//#nosec G304 -- Test code is not controllable by attackers
|
|
||||||
f, err := os.OpenFile(fn, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o600)
|
f, err := os.OpenFile(fn, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open config file: %w", err)
|
return fmt.Errorf("failed to open config file: %w", err)
|
||||||
|
@@ -57,8 +57,6 @@ func SetupLoggingWithFile(fn string, truncate bool) *zap.Logger {
|
|||||||
fl |= os.O_TRUNC
|
fl |= os.O_TRUNC
|
||||||
}
|
}
|
||||||
|
|
||||||
//#nosec G304 -- Test code is not controllable by attackers
|
|
||||||
//#nosec G302 -- Log file should be readable by users
|
|
||||||
f, err := os.OpenFile(fn, fl, 0o644)
|
f, err := os.OpenFile(fn, fl, 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("failed to open log file '%s': %w", fn, err))
|
panic(fmt.Errorf("failed to open log file '%s': %w", fn, err))
|
||||||
|
Reference in New Issue
Block a user