Skip to content

Commit a885a39

Browse files
committed
fix lint errs
1 parent 1ba4492 commit a885a39

9 files changed

Lines changed: 39 additions & 20 deletions

File tree

v2/pkg/runner/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ func createProviderConfigYAML(configFilePath string) error {
1717
if err != nil {
1818
return err
1919
}
20-
defer configFile.Close()
20+
defer func() {
21+
if err := configFile.Close(); err != nil {
22+
gologger.Error().Msgf("Error closing config file: %s", err)
23+
}
24+
}()
2125

2226
sourcesRequiringApiKeysMap := make(map[string][]string)
2327
for _, source := range passive.AllSources {

v2/pkg/runner/outputter.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ func writePlainHostIP(_ string, results map[string]resolve.Result, writer io.Wri
9797

9898
_, err := bufwriter.WriteString(sb.String())
9999
if err != nil {
100-
bufwriter.Flush()
100+
if flushErr := bufwriter.Flush(); flushErr != nil {
101+
return flushErr
102+
}
101103
return err
102104
}
103105
sb.Reset()
@@ -155,7 +157,9 @@ func writePlainHost(_ string, results map[string]resolve.HostEntry, writer io.Wr
155157

156158
_, err := bufwriter.WriteString(sb.String())
157159
if err != nil {
158-
bufwriter.Flush()
160+
if flushErr := bufwriter.Flush(); flushErr != nil {
161+
return flushErr
162+
}
159163
return err
160164
}
161165
sb.Reset()
@@ -228,7 +232,9 @@ func writeSourcePlainHost(_ string, sourceMap map[string]map[string]struct{}, wr
228232

229233
_, err := bufwriter.WriteString(sb.String())
230234
if err != nil {
231-
bufwriter.Flush()
235+
if flushErr := bufwriter.Flush(); flushErr != nil {
236+
return flushErr
237+
}
232238
return err
233239
}
234240
sb.Reset()

v2/pkg/runner/runner.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ func (r *Runner) RunEnumerationWithCtx(ctx context.Context) error {
9494
return err
9595
}
9696
err = r.EnumerateMultipleDomainsWithCtx(ctx, f, outputs)
97-
f.Close()
97+
if closeErr := f.Close(); closeErr != nil {
98+
gologger.Error().Msgf("Error closing file %s: %s", r.options.DomainsFile, closeErr)
99+
}
98100
return err
99101
}
100102

@@ -139,7 +141,9 @@ func (r *Runner) EnumerateMultipleDomainsWithCtx(ctx context.Context, reader io.
139141

140142
_, err = r.EnumerateSingleDomainWithCtx(ctx, domain, append(writers, file))
141143

142-
file.Close()
144+
if closeErr := file.Close(); closeErr != nil {
145+
gologger.Error().Msgf("Error closing file %s: %s", r.options.OutputFile, closeErr)
146+
}
143147
} else if r.options.OutputDirectory != "" {
144148
outputFile := path.Join(r.options.OutputDirectory, domain)
145149
if r.options.JSON {
@@ -157,7 +161,9 @@ func (r *Runner) EnumerateMultipleDomainsWithCtx(ctx context.Context, reader io.
157161

158162
_, err = r.EnumerateSingleDomainWithCtx(ctx, domain, append(writers, file))
159163

160-
file.Close()
164+
if closeErr := file.Close(); closeErr != nil {
165+
gologger.Error().Msgf("Error closing file %s: %s", outputFile, closeErr)
166+
}
161167
} else {
162168
_, err = r.EnumerateSingleDomainWithCtx(ctx, domain, writers)
163169
}

v2/pkg/subscraping/agent.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ func (s *Session) DiscardHTTPResponse(response *http.Response) {
119119
gologger.Warning().Msgf("Could not discard response body: %s\n", err)
120120
return
121121
}
122-
response.Body.Close()
122+
if closeErr := response.Body.Close(); closeErr != nil {
123+
gologger.Warning().Msgf("Could not close response body: %s\n", closeErr)
124+
}
123125
}
124126
}
125127

v2/pkg/subscraping/sources/crtsh/crtsh.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
// postgres driver
1515
_ "github.com/lib/pq"
1616

17+
"github.com/projectdiscovery/gologger"
1718
"github.com/projectdiscovery/subfinder/v2/pkg/subscraping"
1819
contextutil "github.com/projectdiscovery/utils/context"
1920
)
@@ -60,7 +61,11 @@ func (s *Source) getSubdomainsFromSQL(ctx context.Context, domain string, sessio
6061
return 0
6162
}
6263

63-
defer db.Close()
64+
defer func() {
65+
if closeErr := db.Close(); closeErr != nil {
66+
gologger.Warning().Msgf("Could not close database connection: %s\n", closeErr)
67+
}
68+
}()
6469

6570
limitClause := ""
6671
if all, ok := ctx.Value(contextutil.ContextArg("All")).(contextutil.ContextArg); ok {

v2/pkg/subscraping/sources/hunter/hunter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
7373
if err != nil {
7474
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
7575
s.errors++
76-
resp.Body.Close()
76+
session.DiscardHTTPResponse(resp)
7777
return
7878
}
79-
resp.Body.Close()
79+
session.DiscardHTTPResponse(resp)
8080

8181
if response.Code == 401 || response.Code == 400 {
8282
results <- subscraping.Result{

v2/pkg/subscraping/sources/pugrecon/pugrecon.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
8787
if json.NewDecoder(resp.Body).Decode(&apiResp) == nil && apiResp.Message != "" {
8888
errorMsg = fmt.Sprintf("%s: %s", errorMsg, apiResp.Message)
8989
}
90-
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf(errorMsg)}
90+
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf("%s", errorMsg)}
9191
s.errors++
9292
return
9393
}
@@ -100,10 +100,6 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
100100
return
101101
}
102102

103-
if response.Message != "" && !response.Limited { // Handle potential non-error messages, except rate limit info
104-
// Log or handle message if needed, but don't treat as hard error unless necessary
105-
}
106-
107103
for _, subdomain := range response.Results {
108104
results <- subscraping.Result{
109105
Source: s.Name(), Type: subscraping.Subdomain, Value: subdomain.Name,

v2/pkg/subscraping/sources/virustotal/virustotal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
4949
if randomApiKey == "" {
5050
return
5151
}
52-
var cursor string = ""
52+
var cursor = ""
5353
for {
54-
var url string = fmt.Sprintf("https://www.virustotal.com/api/v3/domains/%s/subdomains?limit=40", domain)
54+
var url = fmt.Sprintf("https://www.virustotal.com/api/v3/domains/%s/subdomains?limit=40", domain)
5555
if cursor != "" {
5656
url = fmt.Sprintf("%s&cursor=%s", url, cursor)
5757
}

v2/pkg/subscraping/sources/whoisxmlapi/whoisxmlapi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func (s *Source) Run(ctx context.Context, domain string, session *subscraping.Se
6767
if err != nil {
6868
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}
6969
s.errors++
70-
resp.Body.Close()
70+
session.DiscardHTTPResponse(resp)
7171
return
7272
}
7373

74-
resp.Body.Close()
74+
session.DiscardHTTPResponse(resp)
7575

7676
for _, record := range data.Result.Records {
7777
results <- subscraping.Result{Source: s.Name(), Type: subscraping.Subdomain, Value: record.Domain}

0 commit comments

Comments
 (0)