Skip to content

Commit 908b454

Browse files
committed
fix: resolve remaining errcheck and gosec lint failures
1 parent 503c81f commit 908b454

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

internal/dns/simulate.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import (
88
"time"
99
)
1010

11+
// seededRand is a package-level random source seeded at startup.
12+
// math/rand is appropriate here — simulation output is not security-sensitive.
13+
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec
14+
1115
// SimulateResolution returns a synthetic DNS result without performing any
1216
// network I/O. Common subdomain prefixes resolve ~90% of the time; everything
1317
// else uses the supplied hitRate (0-100).
@@ -21,20 +25,20 @@ func SimulateResolution(domain string, hitRate int, verbose bool) bool {
2125
for _, sub := range commonSubdomains {
2226
if strings.HasPrefix(domain, sub+".") {
2327
if verbose {
24-
fakeTiming := time.Duration(50+rand.Intn(200)) * time.Millisecond
25-
fakeIP := fmt.Sprintf("192.168.%d.%d", rand.Intn(255), 1+rand.Intn(254))
28+
fakeTiming := time.Duration(50+seededRand.Intn(200)) * time.Millisecond
29+
fakeIP := fmt.Sprintf("192.168.%d.%d", seededRand.Intn(255), 1+seededRand.Intn(254))
2630
fmt.Fprintf(os.Stderr, "Resolved (SIMULATED): %s (IP: %s) in %s\n", domain, fakeIP, fakeTiming)
2731
}
28-
return rand.Intn(100) < 90
32+
return seededRand.Intn(100) < 90
2933
}
3034
}
3135

32-
result := rand.Intn(100) < hitRate
36+
result := seededRand.Intn(100) < hitRate
3337

3438
if verbose {
35-
fakeTiming := time.Duration(100+rand.Intn(500)) * time.Millisecond
39+
fakeTiming := time.Duration(100+seededRand.Intn(500)) * time.Millisecond
3640
if result {
37-
fakeIP := fmt.Sprintf("10.%d.%d.%d", rand.Intn(255), rand.Intn(255), 1+rand.Intn(254))
41+
fakeIP := fmt.Sprintf("10.%d.%d.%d", seededRand.Intn(255), seededRand.Intn(255), 1+seededRand.Intn(254))
3842
fmt.Fprintf(os.Stderr, "Resolved (SIMULATED): %s (IP: %s) in %s\n", domain, fakeIP, fakeTiming)
3943
} else {
4044
fmt.Fprintf(os.Stderr, "Failed to resolve (SIMULATED): %s (Error: no such host) in %s\n", domain, fakeTiming)

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,16 @@ func main() {
165165
out.Error("creating output file: %v", err)
166166
os.Exit(1)
167167
}
168-
defer f.Close()
169168
outWriter = bufio.NewWriter(f)
170-
defer outWriter.Flush()
171169
out = output.New(outWriter, *testMode)
170+
defer func() {
171+
if flushErr := outWriter.Flush(); flushErr != nil {
172+
out.Error("flushing output: %v", flushErr)
173+
}
174+
if closeErr := f.Close(); closeErr != nil {
175+
out.Error("closing output file: %v", closeErr)
176+
}
177+
}()
172178
}
173179

174180
if *verbose {

tools/wordlist-gen.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ func main() {
3333
fmt.Printf("Error creating output file: %v\n", err)
3434
os.Exit(1)
3535
}
36-
defer file.Close()
3736

3837
writer := bufio.NewWriter(file)
39-
defer writer.Flush()
38+
defer func() {
39+
if flushErr := writer.Flush(); flushErr != nil {
40+
fmt.Printf("Error flushing writer: %v\n", flushErr)
41+
}
42+
if closeErr := file.Close(); closeErr != nil {
43+
fmt.Printf("Error closing file: %v\n", closeErr)
44+
}
45+
}()
4046

4147
// Track added words to avoid duplicates
4248
addedWords := make(map[string]bool)

0 commit comments

Comments
 (0)